-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and addressed comments from doug
- Loading branch information
Showing
10 changed files
with
125 additions
and
113 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package opentelemetry | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"go.opentelemetry.io/otel" | ||
"google.golang.org/grpc/stats" | ||
otelinternaltracing "google.golang.org/grpc/stats/opentelemetry/internal/tracing" | ||
) | ||
|
||
func (h *clientStatsHandler) initializeTracing() { | ||
if !h.options.isTracingEnabled() { | ||
return | ||
} | ||
|
||
otel.SetTextMapPropagator(h.options.TraceOptions.TextMapPropagator) | ||
otel.SetTracerProvider(h.options.TraceOptions.TracerProvider) | ||
} | ||
|
||
// traceTagRPC populates provided context with a new span using the | ||
// TextMapPropagator supplied in trace options and internal itracing.carrier. | ||
// It creates a new outgoing carrier which serializes information about this | ||
// span into gRPC Metadata, if TextMapPropagator is provided in the trace | ||
// options. if TextMapPropagator is not provided, it returns the context as is. | ||
func (h *clientStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo, ai *attemptInfo) (context.Context, *attemptInfo) { | ||
if h.options.TraceOptions.TextMapPropagator == nil { | ||
return ctx, nil | ||
} | ||
|
||
mn := "Attempt." + strings.Replace(removeLeadingSlash(rti.FullMethodName), "/", ".", -1) | ||
tracer := otel.Tracer("grpc-open-telemetry") | ||
ctx, span := tracer.Start(ctx, mn) | ||
carrier := otelinternaltracing.NewOutgoingCarrier(ctx) | ||
otel.GetTextMapPropagator().Inject(ctx, carrier) | ||
ai.traceSpan = span | ||
return carrier.Context(), ai | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package opentelemetry | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/trace" | ||
"google.golang.org/grpc/stats" | ||
otelinternaltracing "google.golang.org/grpc/stats/opentelemetry/internal/tracing" | ||
) | ||
|
||
func (h *serverStatsHandler) initializeTracing() { | ||
if !h.options.isTracingEnabled() { | ||
return | ||
} | ||
|
||
otel.SetTextMapPropagator(h.options.TraceOptions.TextMapPropagator) | ||
otel.SetTracerProvider(h.options.TraceOptions.TracerProvider) | ||
} | ||
|
||
// traceTagRPC populates context with new span data using the TextMapPropagator | ||
// supplied in trace options and internal itracing.Carrier. It creates a new | ||
// incoming carrier which extracts an existing span context (if present) by | ||
// deserializing from provided context. If valid span context is extracted, it | ||
// is set as parent of the new span otherwise new span remains the root span. | ||
// If TextMapPropagator is not provided in the trace options, it returns context | ||
// as is. | ||
func (h *serverStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo, ai *attemptInfo) (context.Context, *attemptInfo) { | ||
if h.options.TraceOptions.TextMapPropagator == nil { | ||
return ctx, nil | ||
} | ||
|
||
mn := strings.Replace(removeLeadingSlash(rti.FullMethodName), "/", ".", -1) | ||
var span trace.Span | ||
tracer := otel.Tracer("grpc-open-telemetry") | ||
ctx = otel.GetTextMapPropagator().Extract(ctx, otelinternaltracing.NewIncomingCarrier(ctx)) | ||
// If the context.Context provided in `ctx` to tracer.Start(), contains a | ||
// span then the newly-created Span will be a child of that span, | ||
// otherwise it will be a root span. | ||
ctx, span = tracer.Start(ctx, mn, trace.WithSpanKind(trace.SpanKindServer)) | ||
ai.traceSpan = span | ||
return ctx, ai | ||
} |
Oops, something went wrong.