-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add env var TEAMCITY_OTEL_PLUGIN_TRACE_ID to builds
- Loading branch information
1 parent
30f8f5d
commit f9cc7b5
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...r/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildParameterPreProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.octopus.teamcity.opentelemetry.server; | ||
|
||
import jetbrains.buildServer.serverSide.ParametersPreprocessor; | ||
import jetbrains.buildServer.serverSide.SRunningBuild; | ||
import org.apache.log4j.Logger; | ||
import org.apache.logging.log4j.CloseableThreadContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
|
||
public class BuildParameterPreProcessor implements ParametersPreprocessor { | ||
private static final Logger LOG = Logger.getLogger(BuildParameterPreProcessor.class.getName()); | ||
|
||
@NotNull | ||
private final BuildStorageManager buildStorageManager; | ||
|
||
BuildParameterPreProcessor(@NotNull BuildStorageManager buildStorageManager) { | ||
this.buildStorageManager = buildStorageManager; | ||
} | ||
|
||
@Override | ||
public void fixRunBuildParameters(@NotNull SRunningBuild build, @NotNull Map<String, String> runParameters, @NotNull Map<String, String> buildParams) { | ||
try (var ignored = CloseableThreadContext.put("teamcity.build.id", String.valueOf(build.getBuildId()))) { | ||
LOG.debug(String.format("Looking up launch uuid for for build id %d, to add to the build parameters", build.getBuildId())); | ||
var traceId = buildStorageManager.getTraceId(build); | ||
|
||
if (traceId == null) { | ||
LOG.warn(String.format("Unable to get launch uuid for build id %d; we cant set the build parameters", build.getBuildId())); | ||
return; | ||
} | ||
LOG.debug(String.format("Adding trace id '%s' to build parameters for build %d", traceId, build.getBuildId())); | ||
|
||
buildParams.put("env.TEAMCITY_OTEL_PLUGIN_TRACE_ID", traceId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters