-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass tracer in context, traces in POST /decisions
- Loading branch information
1 parent
dee2a2c
commit c0af8c7
Showing
13 changed files
with
199 additions
and
126 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" | ||
gcppropagator "github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator" | ||
"go.opentelemetry.io/contrib/detectors/gcp" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/propagation" | ||
"go.opentelemetry.io/otel/sdk/resource" | ||
sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0" | ||
) | ||
|
||
type Configuration struct { | ||
Enabled bool | ||
ApplicationName string | ||
ProjectID string | ||
} | ||
|
||
func Init(configuration Configuration) error { | ||
if !configuration.Enabled { | ||
return nil | ||
} | ||
|
||
exporter, err := texporter.New(texporter.WithProjectID(configuration.ProjectID)) | ||
if err != nil { | ||
return fmt.Errorf("texporter.New error: %v", err) | ||
} | ||
|
||
res, err := resource.New(context.Background(), | ||
resource.WithDetectors(gcp.NewDetector()), | ||
resource.WithTelemetrySDK(), | ||
resource.WithAttributes( | ||
semconv.ServiceNameKey.String(configuration.ApplicationName), | ||
), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("resource.New error: %w", err) | ||
} | ||
|
||
tp := sdktrace.NewTracerProvider( | ||
sdktrace.WithBatcher(exporter), | ||
sdktrace.WithResource(res), | ||
) | ||
|
||
otel.SetTextMapPropagator( | ||
propagation.NewCompositeTextMapPropagator( | ||
gcppropagator.CloudTraceFormatPropagator{}, | ||
propagation.TraceContext{}, | ||
propagation.Baggage{}, | ||
), | ||
) | ||
otel.SetTracerProvider(tp) | ||
return nil | ||
} | ||
// import ( | ||
// "context" | ||
// "fmt" | ||
|
||
// texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" | ||
// gcppropagator "github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator" | ||
// "go.opentelemetry.io/contrib/detectors/gcp" | ||
// "go.opentelemetry.io/otel" | ||
// "go.opentelemetry.io/otel/propagation" | ||
// "go.opentelemetry.io/otel/sdk/resource" | ||
// sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
// semconv "go.opentelemetry.io/otel/semconv/v1.21.0" | ||
// ) | ||
|
||
// type Configuration struct { | ||
// Enabled bool | ||
// ApplicationName string | ||
// ProjectID string | ||
// } | ||
|
||
// func Init(configuration Configuration) error { | ||
// if !configuration.Enabled { | ||
// return nil | ||
// } | ||
|
||
// exporter, err := texporter.New(texporter.WithProjectID(configuration.ProjectID)) | ||
// if err != nil { | ||
// return fmt.Errorf("texporter.New error: %v", err) | ||
// } | ||
|
||
// res, err := resource.New(context.Background(), | ||
// resource.WithDetectors(gcp.NewDetector()), | ||
// resource.WithTelemetrySDK(), | ||
// resource.WithAttributes( | ||
// semconv.ServiceNameKey.String(configuration.ApplicationName), | ||
// ), | ||
// ) | ||
// if err != nil { | ||
// return fmt.Errorf("resource.New error: %w", err) | ||
// } | ||
|
||
// tp := sdktrace.NewTracerProvider( | ||
// sdktrace.WithBatcher(exporter), | ||
// sdktrace.WithResource(res), | ||
// ) | ||
|
||
// otel.SetTextMapPropagator( | ||
// propagation.NewCompositeTextMapPropagator( | ||
// gcppropagator.CloudTraceFormatPropagator{}, | ||
// propagation.TraceContext{}, | ||
// propagation.Baggage{}, | ||
// ), | ||
// ) | ||
// otel.SetTracerProvider(tp) | ||
// return nil | ||
// } |
This file contains 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 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 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 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 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 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.