Skip to content

Commit

Permalink
Start to add span attributes covered by test
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>
  • Loading branch information
josephwoodward committed Oct 23, 2022
1 parent bac160e commit 75bec98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
9 changes: 8 additions & 1 deletion client/opentelemetry.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (interface{
return submit, err
}

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

Expand All @@ -74,6 +75,12 @@ func createOpenTelemetryClientSpan(op *runtime.ClientOperation, header http.Head
ctx, span = tracer.Start(ctx, operationName(op), opts...)
op.Context = ctx

span.SetAttributes(
attribute.String("http.path", op.PathPattern),
attribute.String("http.method", op.Method),
attribute.String("span.kind", trace.SpanKindClient.String()),
)

return span
}

Expand Down
25 changes: 13 additions & 12 deletions client/opentelemetry_test.go
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"testing"

"github.com/go-openapi/runtime"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"

"github.com/go-openapi/runtime"
)

func Test_OpenTelemetryRuntime_submit(t *testing.T) {
Expand Down Expand Up @@ -81,15 +82,15 @@ func testOpenTelemetrySubmit(t *testing.T, operation *runtime.ClientOperation, e
if expectedSpanCount == 1 {
span := spans[0]
assert.Equal(t, "getCluster", span.Name)
// assert.Equal(t, map[string]interface{}{
// "component": "go-openapi",
// "http.method": "GET",
// "http.path": "/kubernetes-clusters/{cluster_id}",
// "http.status_code": uint16(490),
// "peer.hostname": "remote_host",
// "peer.service": "service",
// "span.kind": ext.SpanKindRPCClientEnum,
// "error": true,
// }, span.Tags())
assert.Equal(t, []attribute.KeyValue{
// "component": "go-openapi",
attribute.String("http.path", "/kubernetes-clusters/{cluster_id}"),
attribute.String("http.method", "GET"),
attribute.String("span.kind", trace.SpanKindClient.String()),
// // "http.status_code": uint16(490),
// "peer.hostname": "remote_host",
// "peer.service": "service",
// "error": true,
}, span.Attributes)
}
}

0 comments on commit 75bec98

Please sign in to comment.