Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Rodriguez Hernandez <[email protected]>
  • Loading branch information
nikita-tkachenko-datadog and drodriguezhdez authored Mar 26, 2024
1 parent af6a44c commit 4a7e2c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public class BuildData implements Serializable {
private Long traceId;
private Long spanId;

@Nullable
private String upstreamPipelineUrl;
@Nullable
private Long upstreamPipelineTraceId;

public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOException, InterruptedException {
Expand Down Expand Up @@ -288,18 +290,18 @@ private void populateUpstreamPipelineData(Run<?, ?> run, EnvVars envVars) {
String upstreamUrl = upstreamCause.getUpstreamUrl();
int upstreamBuild = upstreamCause.getUpstreamBuild();
if (hudsonUrl != null && upstreamUrl != null) {
upstreamPipelineUrl = hudsonUrl + upstreamUrl + upstreamBuild + "/";
this.upstreamPipelineUrl = hudsonUrl + upstreamUrl + upstreamBuild + "/";
}

String upstreamProject = upstreamCause.getUpstreamProject();
if (upstreamProject != null) {
upstreamBuildTag = "jenkins-" + upstreamProject.replace('/', '-') + "-" + upstreamBuild;
this.upstreamBuildTag = "jenkins-" + upstreamProject.replace('/', '-') + "-" + upstreamBuild;

BuildSpanAction buildSpanAction = run.getAction(BuildSpanAction.class);
if (buildSpanAction != null) {
TraceSpan.TraceSpanContext upstreamSpanContext = buildSpanAction.getUpstreamSpanContext();
if (upstreamSpanContext != null) {
upstreamPipelineTraceId = upstreamSpanContext.getTraceId();
this.upstreamPipelineTraceId = upstreamSpanContext.getTraceId();
}
}
}
Expand Down Expand Up @@ -862,10 +864,12 @@ private String getUserEmailByUserId(String userId) {
}
}

@Nullable
public String getUpstreamPipelineUrl() {
return upstreamPipelineUrl;
}

@Nullable
public Long getUpstreamPipelineTraceId() {
return upstreamPipelineTraceId;
}
Expand Down Expand Up @@ -937,11 +941,11 @@ public JSONObject addLogAttributes(){
payload.put("hostname", this.hostname);

if(traceId != null){
payload.put("dd.trace_id", Long.toUnsignedString(traceId));
payload.put("dd.trace_id", Long.toUnsignedString(this.traceId));
}

if(spanId != null) {
payload.put("dd.span_id", Long.toUnsignedString(spanId));
payload.put("dd.span_id", Long.toUnsignedString(this.spanId));
}
return payload;
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BuildSpanAction(final TraceSpan.TraceSpanContext buildSpanContext, @Nulla
this.version = new AtomicInteger(0);
}

public BuildSpanAction(TraceSpan.TraceSpanContext buildSpanContext, TraceSpan.TraceSpanContext upstreamSpanContext, int version, String buildUrl) {
public BuildSpanAction(TraceSpan.TraceSpanContext buildSpanContext, @Nullable TraceSpan.TraceSpanContext upstreamSpanContext, int version, String buildUrl) {
this.buildSpanContext = buildSpanContext;
this.upstreamSpanContext = upstreamSpanContext;
this.version = new AtomicInteger(version);
Expand Down

0 comments on commit 4a7e2c9

Please sign in to comment.