Skip to content

Commit

Permalink
to get a single trace with spans, need to create outter one
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Dec 10, 2022
1 parent 7dbc404 commit 201a5f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion simple/otel_httptrace_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
/*
docker run -p 16686:16686 -p 4317:4317 jaegertracing/all-in-one:latest \
--collector.otlp.enabled=true --collector.otlp.grpc.host-port=:4317
# generate with
OTEL_SERVICE_NAME=test go run .
*/

func installExportPipeline(ctx context.Context) (func(context.Context) error, error) {
Expand All @@ -46,14 +50,15 @@ func installExportPipeline(ctx context.Context) (func(context.Context) error, er

func main() {
ctx := context.Background()
clientTrace := otelhttptrace.NewClientTrace(ctx)
// Registers a tracer Provider globally.
shutdown, err := installExportPipeline(ctx)
if err != nil {
log.Fatalf("Error setting up export pipeline: %v", err)
}
log.Printf("OTEL export pipeline setup successfully")

ctx, span := otel.Tracer("github.com/fortio/fortiotel").Start(ctx, "main")
clientTrace := otelhttptrace.NewClientTrace(ctx)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://www.google.com/", nil)
if err != nil {
log.Fatalf("Error creating request: %v", err)
Expand All @@ -68,6 +73,7 @@ func main() {
log.Fatalf("Error reading response body: %v", err)
}
_ = resp.Body.Close()
span.End()
if err := shutdown(context.Background()); err != nil {
log.Fatalf("Error shutting down up export pipeline: %v", err)
}
Expand Down

0 comments on commit 201a5f6

Please sign in to comment.