Skip to content

Commit

Permalink
default tracer provider
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Aug 29, 2024
1 parent 4234b76 commit 941c904
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

package software.amazon.smithy.go.codegen.integration;

import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol;

import java.util.List;
import software.amazon.smithy.go.codegen.GoCodegenContext;
import software.amazon.smithy.go.codegen.SmithyGoDependency;

/**
Expand All @@ -28,6 +32,12 @@ public class ObservabilityOptions implements GoIntegration {
.documentation("The client tracer provider.")
.build();

private static final ConfigFieldResolver RESOLVE_TRACER_PROVIDER = ConfigFieldResolver.builder()
.resolver(buildPackageSymbol("resolveTracerProvider"))
.location(ConfigFieldResolver.Location.CLIENT)
.target(ConfigFieldResolver.Target.INITIALIZATION)
.build();

// TODO
// private static final ConfigField METER_PROVIDER = ConfigField.builder()
// .name("MeterProvider")
Expand All @@ -40,7 +50,19 @@ public List<RuntimeClientPlugin> getClientPlugins() {
return List.of(
RuntimeClientPlugin.builder()
.addConfigField(TRACER_PROVIDER)
.addConfigFieldResolver(RESOLVE_TRACER_PROVIDER)
.build()
);
}

@Override
public void writeAdditionalFiles(GoCodegenContext ctx) {
ctx.writerDelegator().useFileWriter("api_client.go", ctx.settings().getModuleName(), goTemplate("""
func resolveTracerProvider(options *Options) {
if options.TracerProvider == nil {
options.TracerProvider = &$T{}
}
}
""", SmithyGoDependency.SMITHY_TRACING.struct("NopTracerProvider")));
}
}

0 comments on commit 941c904

Please sign in to comment.