-
Notifications
You must be signed in to change notification settings - Fork 75
refactor(o11y): merge SpanTracer and SpanManager #4158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,25 +33,27 @@ | |
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.api.trace.Tracer; | ||
|
|
||
| /** | ||
| * A {@link ApiTracerFactory} to build instances of {@link SpanTracer}. | ||
| * | ||
| * <p>This class wraps the {@link TraceManager} and pass it to {@link SpanTracer}. It will be used | ||
| * to record traces in {@link SpanTracer}. | ||
| * <p>This class wraps the {@link Tracer} and pass it to {@link SpanTracer}. It will be used to | ||
| * record traces in {@link SpanTracer}. | ||
| * | ||
| * <p>This class is expected to be initialized once during client initialization. | ||
| */ | ||
| @BetaApi | ||
| @InternalApi | ||
| public class SpanTracerFactory implements ApiTracerFactory { | ||
| private final TraceManager traceManager; | ||
| private final Tracer tracer; | ||
|
|
||
| private final ApiTracerContext apiTracerContext; | ||
|
|
||
| /** Creates a SpanTracerFactory */ | ||
| public SpanTracerFactory(TraceManager traceManager) { | ||
| this(traceManager, ApiTracerContext.empty()); | ||
| public SpanTracerFactory(OpenTelemetry openTelemetry) { | ||
| this(openTelemetry.getTracer("gax-java"), ApiTracerContext.empty()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -60,8 +62,8 @@ public SpanTracerFactory(TraceManager traceManager) { | |
| * internally. | ||
| */ | ||
| @VisibleForTesting | ||
| SpanTracerFactory(TraceManager traceManager, ApiTracerContext apiTracerContext) { | ||
| this.traceManager = traceManager; | ||
| SpanTracerFactory(Tracer tracer, ApiTracerContext apiTracerContext) { | ||
| this.tracer = tracer; | ||
| this.apiTracerContext = apiTracerContext; | ||
| } | ||
|
|
||
|
|
@@ -71,28 +73,13 @@ public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType op | |
| // feature is developed. | ||
| String attemptSpanName = spanName.getClientName() + "/" + spanName.getMethodName() + "/attempt"; | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SpanTracer spanTracer = new SpanTracer(traceManager, this.apiTracerContext, attemptSpanName); | ||
| return spanTracer; | ||
| return new SpanTracer(tracer, this.apiTracerContext, attemptSpanName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this PR, I think we should reconsider the need of overriding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
| } | ||
|
|
||
| @Override | ||
| public ApiTracer newTracer(ApiTracer parent, ApiTracerContext apiTracerContext) { | ||
| ApiTracerContext mergedContext = this.apiTracerContext.merge(apiTracerContext); | ||
|
|
||
| String attemptSpanName; | ||
| if (mergedContext.transport() == ApiTracerContext.Transport.GRPC) { | ||
| // gRPC Uses the full method name as span name. | ||
| attemptSpanName = mergedContext.fullMethodName(); | ||
| } else if (mergedContext.httpMethod() == null || mergedContext.httpPathTemplate() == null) { | ||
| // HTTP method name without necessary components defaults to the full method name | ||
| attemptSpanName = mergedContext.fullMethodName(); | ||
| } else { | ||
| // We construct the span name with HTTP method and path template. | ||
| attemptSpanName = | ||
| String.format("%s %s", mergedContext.httpMethod(), mergedContext.httpPathTemplate()); | ||
| } | ||
|
|
||
| return new SpanTracer(traceManager, mergedContext, attemptSpanName); | ||
| return new SpanTracer(tracer, mergedContext); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -102,6 +89,6 @@ public ApiTracerContext getApiTracerContext() { | |
|
|
||
| @Override | ||
| public ApiTracerFactory withContext(ApiTracerContext context) { | ||
| return new SpanTracerFactory(traceManager, apiTracerContext.merge(context)); | ||
| return new SpanTracerFactory(tracer, apiTracerContext.merge(context)); | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not part of this PR, we want to create a tracer with artifact name and version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.