Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use semconv in integration tests #660

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/integration/components/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"regexp"
"strings"

"go.opentelemetry.io/otel/attribute"
)

type TracesQuery struct {
Expand Down Expand Up @@ -193,3 +195,19 @@ func DiffAsRegexp(expected, actual []Tag) DiffResult {
}
return dr
}

func TagFromOtel(kv attribute.KeyValue) Tag {
return Tag{
Key: string(kv.Key),
Type: kv.Value.Type().String(),
Value: kv.Value.AsInterface(),
}
}

func TagsFromOtel(kvs []attribute.KeyValue) []Tag {
tags := make([]Tag, len(kvs))
for i, kv := range kvs {
tags[i] = TagFromOtel(kv)
}
return tags
}
48 changes: 26 additions & 22 deletions test/integration/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/mariomac/guara/pkg/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"

"github.com/grafana/beyla/test/integration/components/jaeger"
grpcclient "github.com/grafana/beyla/test/integration/components/testserver/grpc/client"
Expand Down Expand Up @@ -55,7 +57,7 @@ func testHTTPTracesCommon(t *testing.T, doTraceID bool, httpCode int) {
require.Equal(t, http.StatusOK, resp.StatusCode)
var tq jaeger.TracesQuery
require.NoError(t, json.NewDecoder(resp.Body).Decode(&tq))
traces := tq.FindBySpan(jaeger.Tag{Key: "url.path", Type: "string", Value: "/" + slug})
traces := tq.FindBySpan(jaeger.TagFromOtel(semconv.URLPath("/" + slug)))
require.Len(t, traces, 1)
trace = traces[0]
require.Len(t, trace.Spans, 3) // parent - in queue - processing
Expand All @@ -76,20 +78,20 @@ func testHTTPTracesCommon(t *testing.T, doTraceID bool, httpCode int) {
// check duration is at least 10ms
assert.Less(t, (10 * time.Millisecond).Microseconds(), parent.Duration)
// check span attributes
sd := parent.Diff(
jaeger.Tag{Key: "http.request.method", Type: "string", Value: "GET"},
jaeger.Tag{Key: "http.response.status_code", Type: "int64", Value: float64(httpCode)},
jaeger.Tag{Key: "url.path", Type: "string", Value: "/" + slug},
jaeger.Tag{Key: "server.port", Type: "int64", Value: float64(8080)},
jaeger.Tag{Key: "http.route", Type: "string", Value: "/" + slug},
tags := append(
jaeger.TagsFromOtel([]attribute.KeyValue{
semconv.HTTPRequestMethodGet,
semconv.HTTPResponseStatusCode(httpCode),
semconv.ServerPort(8080),
semconv.HTTPRoute("/" + slug),
}),
jaeger.Tag{Key: "span.kind", Type: "string", Value: "server"},
)
sd := parent.Diff(tags...)
assert.Empty(t, sd, sd.String())

if httpCode >= 500 {
sd := parent.Diff(
jaeger.Tag{Key: "otel.status_code", Type: "string", Value: "ERROR"},
)
sd := parent.Diff(jaeger.TagFromOtel(semconv.OTelStatusCodeError))
assert.Empty(t, sd, sd.String())
}

Expand All @@ -107,7 +109,7 @@ func testHTTPTracesCommon(t *testing.T, doTraceID bool, httpCode int) {
assert.LessOrEqual(t,
queue.StartTime+queue.Duration,
parent.StartTime+parent.Duration+1) // adding 1 to tolerate inaccuracies from rounding from ns to ms
// check span attributes

// check span attributes
sd = queue.Diff(
jaeger.Tag{Key: "span.kind", Type: "string", Value: "internal"},
Expand Down Expand Up @@ -145,10 +147,10 @@ func testHTTPTracesCommon(t *testing.T, doTraceID bool, httpCode int) {
assert.Regexp(t, `^beyla-\d+$`, serviceInstance.Value)

jaeger.Diff([]jaeger.Tag{
{Key: "otel.library.name", Type: "string", Value: "github.com/grafana/beyla"},
{Key: "telemetry.sdk.language", Type: "string", Value: "go"},
{Key: "telemetry.sdk.name", Type: "string", Value: "beyla"},
{Key: "service.namespace", Type: "string", Value: "integration-test"},
jaeger.TagFromOtel(semconv.OTelScopeName("github.com/grafana/beyla")),
jaeger.TagFromOtel(semconv.TelemetrySDKLanguageGo),
jaeger.TagFromOtel(semconv.TelemetrySDKName("beyla")),
jaeger.TagFromOtel(semconv.ServiceNamespace("integration-test")),
serviceInstance,
}, process.Tags)
assert.Empty(t, sd, sd.String())
Expand All @@ -162,7 +164,7 @@ func testHTTPTracesCommon(t *testing.T, doTraceID bool, httpCode int) {
require.Equal(t, http.StatusOK, resp.StatusCode)
var tq jaeger.TracesQuery
require.NoError(t, json.NewDecoder(resp.Body).Decode(&tq))
traces := tq.FindBySpan(jaeger.Tag{Key: "url.path", Type: "string", Value: "/metrics"})
traces := tq.FindBySpan(jaeger.TagFromOtel(semconv.URLPath("/metrics")))
require.Len(t, traces, 0)
}

Expand All @@ -180,7 +182,7 @@ func testGRPCTracesForServiceName(t *testing.T, svcName string) {
require.Equal(t, http.StatusOK, resp.StatusCode)
var tq jaeger.TracesQuery
require.NoError(t, json.NewDecoder(resp.Body).Decode(&tq))
traces := tq.FindBySpan(jaeger.Tag{Key: "rpc.method", Type: "string", Value: "/routeguide.RouteGuide/Debug"})
traces := tq.FindBySpan(jaeger.TagFromOtel(semconv.RPCMethod("/routeguide.RouteGuide/Debug")))
require.Len(t, traces, 1)
trace = traces[0]
require.Len(t, trace.Spans, 3) // parent - in queue - processing
Expand All @@ -195,13 +197,15 @@ func testGRPCTracesForServiceName(t *testing.T, svcName string) {
// check duration is at least 10ms (10,000 microseconds)
assert.Less(t, (10 * time.Millisecond).Microseconds(), parent.Duration)
// check span attributes
sd := parent.Diff(
jaeger.Tag{Key: "server.port", Type: "int64", Value: float64(5051)},
jaeger.Tag{Key: "rpc.grpc.status_code", Type: "int64", Value: float64(2)},
jaeger.Tag{Key: "rpc.method", Type: "string", Value: "/routeguide.RouteGuide/Debug"},
jaeger.Tag{Key: "rpc.system", Type: "string", Value: "grpc"},
tags := append(
jaeger.TagsFromOtel([]attribute.KeyValue{
semconv.ServerPort(5051),
semconv.RPCGRPCStatusCodeUnknown,
semconv.RPCMethod("/routeguide.RouteGuide/Debug"),
semconv.RPCSystemGRPC}),
jaeger.Tag{Key: "span.kind", Type: "string", Value: "server"},
)
sd := parent.Diff(tags...)
assert.Empty(t, sd, sd.String())

// Check the information of the "in queue" span
Expand Down