Skip to content

Commit

Permalink
Add scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwoodward committed Oct 28, 2022
1 parent e97982b commit 9a080fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions client/opentelemetry.go
Expand Up @@ -67,23 +67,26 @@ func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (interface{

func createOpenTelemetryClientSpan(op *runtime.ClientOperation, _ http.Header, host string, opts []trace.SpanStartOption) trace.Span {
ctx := op.Context
span := trace.SpanFromContext(ctx)

if span != nil {
if span := trace.SpanFromContext(ctx); span.IsRecording() {
// TODO: Can we get the version number for use with trace.WithInstrumentationVersion?
tracer := otel.GetTracerProvider().Tracer("")

ctx, span = tracer.Start(ctx, operationName(op), opts...)
op.Context = ctx

//TODO: There's got to be a better way to do this without the request, right?
var scheme string
if len(op.Schemes) == 1 {
scheme = op.Schemes[0]
}

span.SetAttributes(
attribute.String("net.peer.name", host),
// attribute.String("net.peer.port", ""),
attribute.String(string(semconv.HTTPRouteKey), op.PathPattern),
attribute.String(string(semconv.HTTPMethodKey), op.Method),
attribute.String("span.kind", trace.SpanKindClient.String()),
//TODO: Figure out the best way to get the scheme?
attribute.String("http.scheme", op.Schemes[0]),
attribute.String("http.scheme", scheme),
)

return span
Expand Down
1 change: 0 additions & 1 deletion client/opentelemetry_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/go-openapi/runtime"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
Expand Down
5 changes: 3 additions & 2 deletions client/runtime.go
Expand Up @@ -31,13 +31,14 @@ import (
"sync"
"time"

"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel/trace"

"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/logger"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/runtime/yamlpc"
"github.com/go-openapi/strfmt"
"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel/trace"
)

// TLSClientOptions to configure client authentication with mutual TLS
Expand Down

0 comments on commit 9a080fa

Please sign in to comment.