This repository was archived by the owner on May 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
refactor(o11y): merge SpanTracer and SpanManager #4158
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 0 additions & 79 deletions
79
gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTraceManager.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -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.
|
||
|
|
||
| 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)); | ||
| } | ||
| } | ||
50 changes: 0 additions & 50 deletions
50
gax-java/gax/src/main/java/com/google/api/gax/tracing/TraceManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.