Skip to content

Commit

Permalink
Merge branch 'shahzaibj/temp/sampling-improvements' into shahzaibj/sa…
Browse files Browse the repository at this point in the history
…mpling-improvements
  • Loading branch information
shahzaibj committed Jan 29, 2024
2 parents 25ef7ab + 5a3a5af commit b7ebbf4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,10 @@ public enum AttributeName {
/**
* Indicates the request sequence used by cached credential service (if used) on server side
*/
ccs_request_sequence
ccs_request_sequence,

/**
* Indicates the package name of the app making the request to the broker.
*/
calling_package_name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public static Span createSpan(@NonNull final String name) {
return tracer.spanBuilder(name).startSpan();
}

/**
* Creates a span (with shared basic attributes).
**/
@NonNull
public static Span createSpan(@NonNull final String name, @NonNull final String callingPackageName) {
final Tracer tracer = OpenTelemetryHolder.getTracer(TAG);
return tracer.spanBuilder(name)
.setAttribute(AttributeName.calling_package_name.name(), callingPackageName)
.startSpan();
}

/**
* Creates a span from a parent Span Context (with shared basic attributes).
**/
Expand All @@ -71,6 +82,33 @@ public static Span createSpanFromParent(@NonNull final String name,
.startSpan();
}

/**
* Creates a span from a parent Span Context (with shared basic attributes).
**/
@NonNull
public static Span createSpanFromParent(@NonNull final String name,
@Nullable final SpanContext parentSpanContext,
@NonNull final String callingPackageName) {
final String methodTag = TAG + ":createSpanFromParent";

if (parentSpanContext == null) {
Logger.verbose(methodTag, "parentSpanContext is NULL. Creating span without parent.");
return createSpan(name, callingPackageName);
}

if (!parentSpanContext.isValid()) {
Logger.warn(methodTag, "parentSpanContext is INVALID. Creating span without parent.");
return createSpan(name, callingPackageName);
}

final Tracer tracer = OpenTelemetryHolder.getTracer(TAG);

return tracer.spanBuilder(name)
.setParent(Context.current().with(Span.wrap(parentSpanContext)))
.setAttribute(AttributeName.calling_package_name.name(), callingPackageName)
.startSpan();
}

/**
* Creates a span (with shared basic attributes).
**/
Expand Down

0 comments on commit b7ebbf4

Please sign in to comment.