-
Notifications
You must be signed in to change notification settings - Fork 73
feat(obs): introduce gpc.client.repo span attribute #4111
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
Draft
diegomarquezp
wants to merge
61
commits into
main
Choose a base branch
from
observability/tracing-attr/repo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
7082247
feat: introduce minimal implementation of OTel tracing
diegomarquezp bfe6a6d
chore: avoid new public methods
diegomarquezp ea6cb18
feat: add api tracer context
diegomarquezp 97bec08
Merge remote-tracking branch 'origin/main' into observability/initial…
diegomarquezp 097f701
chore: concise comment
diegomarquezp f547e5a
fix: use internal span kind for operations
diegomarquezp b7b9e31
chore: remove unnecessary inScope implementation
diegomarquezp 556c84c
Revert "chore: remove unnecessary inScope implementation"
diegomarquezp 0359b7d
test: add test for inScope()
diegomarquezp 402cb89
Merge remote-tracking branch 'origin/main' into observability/initial…
diegomarquezp 420278b
chore: use suggested server address resolution impl
diegomarquezp 6de9fb6
fix: use concurrent hash map
diegomarquezp a61dacf
chore: remove default impl for startSpan with parent
diegomarquezp b000d52
chore: add opentelemery-context to tests
diegomarquezp 9ce0c34
test: increase coverage for TracingTracerTest
diegomarquezp 9c6c737
deps: include opentelemetry context in gax
diegomarquezp e77de58
chore: simplify and remove error handling
diegomarquezp 8f07f61
chore: review refactor
diegomarquezp 2cfcd68
chore: make TracingTracerFactory(recorder, opAtts, atAtts) package pr…
diegomarquezp 2415c6b
chore: remove unnecessary inScope
diegomarquezp 0f5e9b5
chore: rename startSpan to createSpan
diegomarquezp 0c3bd22
chore: use server address instead of endpoint context
diegomarquezp bdeb291
chore: rename classes
diegomarquezp 5c07a3c
chore: add javadoc for tracer
diegomarquezp ff1d45d
chore: rename to TraceSpan, improve javadocs
diegomarquezp 043ce62
chore: format
diegomarquezp dbc5f41
Update gax-java/gax/src/main/java/com/google/api/gax/tracing/AppCentr…
diegomarquezp b4bce0d
chore: handle ipv6 in endpoint context
diegomarquezp 6e95cf4
Merge branch 'observability/initial-tracing-impl' of https://github.c…
diegomarquezp e873904
chore: add language tests
diegomarquezp 68943b0
chore: AppCentricTracer to implement interface
diegomarquezp ba3c080
feat(obs): generate gapic.properties file with repo property
diegomarquezp caead0d
feat: implement repo handling in gax
diegomarquezp 58f72d2
test: add tests for repo property
diegomarquezp 5a5d9d6
chore: speed up image building
diegomarquezp 015aa88
build: introduce repo property to generation config
diegomarquezp 0907e93
chore: update showcase module
diegomarquezp cd4d4d0
chore: revert operation implementation
diegomarquezp 5b76e40
chore: extract common span attributes to separate class
diegomarquezp c783d68
chore: remove unused var
diegomarquezp 1eeb197
Merge branch 'observability/initial-tracing-impl' into observability/…
diegomarquezp d2bd03c
chore(obs): use `Span` instead of `AppCentric` prefix for tracing
diegomarquezp 13f9bb3
Merge branch 'observability/rename-to-span' into observability/tracin…
diegomarquezp beee741
chore: use ApiTracerContext for this
diegomarquezp c2acaaf
feat: add ApiTracerContext client specific subclass generation
diegomarquezp c60da4c
chore: update goldens
diegomarquezp e3be9f4
chore: fix ApiTraceContext subclass generation
diegomarquezp da35f97
chore: regenerate showcase
diegomarquezp 2983e30
chore: fix default var in generate_library.sh
diegomarquezp f0e17ac
chore: infer server address directly from StubSettings
diegomarquezp 55e4be1
chore: adapt to stubsettings inferring server address
diegomarquezp 4aa17c4
chore: revert changes and pass server address from ClientContext
diegomarquezp 079d1f5
chore: update goldens
diegomarquezp 8601b76
chore: generate libraries at Fri Feb 20 18:31:23 UTC 2026
cloud-java-bot a0fcd28
chore: regenerate showcase
diegomarquezp 4b6e9ae
Merge branch 'observability/tracing-attr/repo' of https://github.com/…
diegomarquezp c413fbf
chore: fix type hint
diegomarquezp 63e6ee6
chore: optimize for reliability scanner
diegomarquezp bac45b3
chore: delete old class
diegomarquezp f3f14c9
chore: simplify apitracercontext
diegomarquezp 2357560
chore: simplify apitracercontext
diegomarquezp 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
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
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
205 changes: 205 additions & 0 deletions
205
.../com/google/api/generator/gapic/composer/common/ServiceApiTracerContextClassComposer.java
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 |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.api.generator.gapic.composer.common; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.api.gax.tracing.ApiTracerContext; | ||
| import com.google.api.generator.engine.ast.AnnotationNode; | ||
| import com.google.api.generator.engine.ast.AssignmentExpr; | ||
| import com.google.api.generator.engine.ast.ClassDefinition; | ||
| import com.google.api.generator.engine.ast.Expr; | ||
| import com.google.api.generator.engine.ast.ExprStatement; | ||
| import com.google.api.generator.engine.ast.MethodDefinition; | ||
| import com.google.api.generator.engine.ast.ScopeNode; | ||
| import com.google.api.generator.engine.ast.Statement; | ||
| import com.google.api.generator.engine.ast.StringObjectValue; | ||
| import com.google.api.generator.engine.ast.ThisObjectValue; | ||
| import com.google.api.generator.engine.ast.TypeNode; | ||
| import com.google.api.generator.engine.ast.ValueExpr; | ||
| import com.google.api.generator.engine.ast.Variable; | ||
| import com.google.api.generator.engine.ast.VariableExpr; | ||
| import com.google.api.generator.gapic.composer.store.TypeStore; | ||
| import com.google.api.generator.gapic.composer.utils.ClassNames; | ||
| import com.google.api.generator.gapic.model.GapicClass; | ||
| import com.google.api.generator.gapic.model.GapicContext; | ||
| import com.google.api.generator.gapic.model.Service; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import javax.annotation.Generated; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Composes a service-specific implementation of {@link ApiTracerContext}. | ||
| * | ||
| * <p>The generated class is used to provide client-library-specific attributes (like the repository | ||
| * URL) to {@link com.google.api.gax.tracing.ApiTracer}s. | ||
| */ | ||
| public class ServiceApiTracerContextClassComposer implements ClassComposer { | ||
| private static final ServiceApiTracerContextClassComposer INSTANCE = | ||
| new ServiceApiTracerContextClassComposer(); | ||
|
|
||
| private static final TypeStore FIXED_TYPESTORE = createStaticTypes(); | ||
|
|
||
| private ServiceApiTracerContextClassComposer() {} | ||
|
|
||
| public static ServiceApiTracerContextClassComposer instance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public GapicClass generate(GapicContext context, Service service) { | ||
| String pakkage = String.format("%s.stub", service.pakkage()); | ||
| String className = ClassNames.getServiceApiTracerContextClassName(service); | ||
| TypeStore typeStore = createDynamicTypes(service, pakkage); | ||
|
|
||
| ClassDefinition classDef = | ||
| ClassDefinition.builder() | ||
| .setPackageString(pakkage) | ||
| .setAnnotations(createClassAnnotations()) | ||
| .setScope(ScopeNode.PUBLIC) | ||
| .setName(className) | ||
| .setExtendsType(FIXED_TYPESTORE.get("ApiTracerContext")) | ||
| .setStatements(createClassStatements()) | ||
| .setMethods(createClassMethods(service, context, typeStore)) | ||
| .build(); | ||
|
|
||
| return GapicClass.create(GapicClass.Kind.STUB, classDef); | ||
| } | ||
|
|
||
| private static List<AnnotationNode> createClassAnnotations() { | ||
| return Arrays.asList( | ||
| AnnotationNode.withType(FIXED_TYPESTORE.get("InternalApi")), | ||
| AnnotationNode.withType(FIXED_TYPESTORE.get("BetaApi")), | ||
| AnnotationNode.builder() | ||
| .setType(FIXED_TYPESTORE.get("Generated")) | ||
| .setDescription("by gapic-generator-java") | ||
| .build()); | ||
| } | ||
|
|
||
| private static List<Statement> createClassStatements() { | ||
| VariableExpr serverAddressVarExpr = | ||
| VariableExpr.withVariable( | ||
| Variable.builder().setType(TypeNode.STRING).setName("serverAddress").build()); | ||
| return Arrays.asList( | ||
| ExprStatement.withExpr( | ||
| serverAddressVarExpr.toBuilder() | ||
| .setIsDecl(true) | ||
| .setScope(ScopeNode.PRIVATE) | ||
| .setIsFinal(true) | ||
| .build())); | ||
| } | ||
|
|
||
| private static List<MethodDefinition> createClassMethods( | ||
| Service service, GapicContext context, TypeStore typeStore) { | ||
| List<MethodDefinition> methods = new ArrayList<>(); | ||
| methods.add(createConstructor(service, typeStore)); | ||
| methods.add(createCreateMethod(service, typeStore)); | ||
| methods.add(createGetServerAddressMethod()); | ||
| methods.add(createGetRepoMethod(context)); | ||
| return methods; | ||
| } | ||
|
|
||
| private static MethodDefinition createConstructor(Service service, TypeStore typeStore) { | ||
| TypeNode thisType = typeStore.get(ClassNames.getServiceApiTracerContextClassName(service)); | ||
| VariableExpr serverAddressVarExpr = | ||
| VariableExpr.withVariable( | ||
| Variable.builder().setType(TypeNode.STRING).setName("serverAddress").build()); | ||
|
|
||
| VariableExpr thisServerAddressVarExpr = | ||
| VariableExpr.builder() | ||
| .setVariable(serverAddressVarExpr.variable()) | ||
| .setExprReferenceExpr(ValueExpr.withValue(ThisObjectValue.withType(thisType))) | ||
| .build(); | ||
|
|
||
| return MethodDefinition.constructorBuilder() | ||
| .setScope(ScopeNode.PRIVATE) | ||
| .setReturnType(thisType) | ||
| .setArguments(serverAddressVarExpr.toBuilder().setIsDecl(true).build()) | ||
| .setBody( | ||
| Arrays.asList( | ||
| ExprStatement.withExpr( | ||
| AssignmentExpr.builder() | ||
| .setVariableExpr(thisServerAddressVarExpr) | ||
| .setValueExpr(serverAddressVarExpr) | ||
| .build()))) | ||
| .build(); | ||
| } | ||
|
|
||
| private static MethodDefinition createCreateMethod(Service service, TypeStore typeStore) { | ||
| TypeNode thisType = typeStore.get(ClassNames.getServiceApiTracerContextClassName(service)); | ||
| VariableExpr serverAddressVarExpr = | ||
| VariableExpr.withVariable( | ||
| Variable.builder().setType(TypeNode.STRING).setName("serverAddress").build()); | ||
|
|
||
| return MethodDefinition.builder() | ||
| .setScope(ScopeNode.PUBLIC) | ||
| .setIsStatic(true) | ||
| .setReturnType(thisType) | ||
| .setName("create") | ||
| .setArguments(serverAddressVarExpr.toBuilder().setIsDecl(true).build()) | ||
| .setReturnExpr( | ||
| com.google.api.generator.engine.ast.NewObjectExpr.builder() | ||
| .setType(thisType) | ||
| .setArguments(serverAddressVarExpr) | ||
| .build()) | ||
| .build(); | ||
| } | ||
|
|
||
| private static MethodDefinition createGetServerAddressMethod() { | ||
| return MethodDefinition.builder() | ||
| .setIsOverride(true) | ||
| .setScope(ScopeNode.PUBLIC) | ||
| .setReturnType(TypeNode.STRING) | ||
| .setName("getServerAddress") | ||
| .setReturnExpr( | ||
| VariableExpr.withVariable( | ||
| Variable.builder().setType(TypeNode.STRING).setName("serverAddress").build())) | ||
| .build(); | ||
| } | ||
|
|
||
| private static MethodDefinition createGetRepoMethod(GapicContext context) { | ||
| Expr returnExpr = ValueExpr.createNullExpr(); | ||
| if (context.repo().isPresent()) { | ||
| returnExpr = ValueExpr.withValue(StringObjectValue.withValue(context.repo().get())); | ||
| } | ||
| return MethodDefinition.builder() | ||
| .setIsOverride(true) | ||
| .setScope(ScopeNode.PUBLIC) | ||
| .setReturnType(TypeNode.STRING) | ||
| .setName("getRepo") | ||
| .setReturnExpr(returnExpr) | ||
| .build(); | ||
| } | ||
|
|
||
| private static TypeStore createStaticTypes() { | ||
| return new TypeStore( | ||
| Arrays.asList( | ||
| BetaApi.class, | ||
| InternalApi.class, | ||
| Generated.class, | ||
| ApiTracerContext.class, | ||
| Nullable.class)); | ||
| } | ||
|
|
||
| private TypeStore createDynamicTypes(Service service, String pakkage) { | ||
| TypeStore typeStore = new TypeStore(); | ||
| typeStore.put(pakkage, ClassNames.getServiceApiTracerContextClassName(service)); | ||
| return typeStore; | ||
| } | ||
| } |
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
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
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.
The
parseRepomethod usesparseConfigArgument, which parses plugin arguments by splitting the input string by commas. If therepovalue contains a comma, it will be split, potentially allowing an attacker to inject additional plugin flags or options (e.g., injecting,metadatato enable metadata generation).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.
I don't think that's how the argument parser will work. If repo contains a comma then what's after the comma will be ignored and treated as a sperate flag not handled by the generator.