From e390757e04c01d18938da04df4678f27759bb4ab Mon Sep 17 00:00:00 2001 From: Joseph Woodward Date: Wed, 26 Oct 2022 05:07:49 +0100 Subject: [PATCH] Continue to work on setting appropriate attributes Signed-off-by: Joseph Woodward --- client/opentelemetry.go | 8 +++++--- client/opentelemetry_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/opentelemetry.go b/client/opentelemetry.go index a98d0147..29e4f2ca 100644 --- a/client/opentelemetry.go +++ b/client/opentelemetry.go @@ -65,7 +65,7 @@ func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (interface{ return submit, err } -func createOpenTelemetryClientSpan(op *runtime.ClientOperation, _ http.Header, _ string, opts []trace.SpanStartOption) trace.Span { +func createOpenTelemetryClientSpan(op *runtime.ClientOperation, _ http.Header, host string, opts []trace.SpanStartOption) trace.Span { ctx := op.Context span := trace.SpanFromContext(ctx) @@ -77,11 +77,13 @@ func createOpenTelemetryClientSpan(op *runtime.ClientOperation, _ http.Header, _ op.Context = ctx 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: Get scheme reliably from header - attribute.String("http.scheme", "https"), + //TODO: Figure out the best way to get the scheme? + attribute.String("http.scheme", op.Schemes[0]), ) return span diff --git a/client/opentelemetry_test.go b/client/opentelemetry_test.go index 2000f6b5..ef7e0843 100644 --- a/client/opentelemetry_test.go +++ b/client/opentelemetry_test.go @@ -86,12 +86,12 @@ func assertOpenTelemetrySubmit(t *testing.T, operation *runtime.ClientOperation, assert.Equal(t, span.Status.Code, codes.Error) assert.Equal(t, []attribute.KeyValue{ // "component": "go-openapi", + attribute.String("net.peer.name", "remote_host"), attribute.String("http.route", "/kubernetes-clusters/{cluster_id}"), attribute.String("http.method", "GET"), attribute.String("span.kind", trace.SpanKindClient.String()), attribute.String("http.scheme", "https"), attribute.Int("http.status_code", 490), - // "peer.hostname": "remote_host", // "peer.service": "service", // "error": true, }, span.Attributes)