Skip to content

Commit

Permalink
report Beyla version in OTEL traces and metrics (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomac authored Jan 17, 2025
1 parent eb0cd64 commit 05851de
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/export/otel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"
"google.golang.org/grpc/credentials"

"github.com/grafana/beyla/pkg/buildinfo"
"github.com/grafana/beyla/pkg/export/attributes"
"github.com/grafana/beyla/pkg/export/expire"
"github.com/grafana/beyla/pkg/internal/svc"
Expand Down Expand Up @@ -76,6 +77,7 @@ func getResourceAttrs(hostID string, service *svc.Attrs) []attribute.KeyValue {
semconv.TelemetrySDKLanguageKey.String(service.SDKLanguage.String()),
// We set the SDK name as Beyla, so we can distinguish beyla generated metrics from other SDKs
semconv.TelemetrySDKNameKey.String("beyla"),
semconv.TelemetrySDKVersion(buildinfo.Version),
semconv.HostName(service.HostName),
semconv.HostID(hostID),
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/export/otel/metrics_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"

"github.com/grafana/beyla/pkg/buildinfo"
"github.com/grafana/beyla/pkg/export/attributes"
"github.com/grafana/beyla/pkg/export/expire"
"github.com/grafana/beyla/pkg/export/otel/metric"
Expand Down Expand Up @@ -47,6 +48,7 @@ func newResource(hostID string) *resource.Resource {
semconv.TelemetrySDKLanguageKey.String(semconv.TelemetrySDKLanguageGo.Value.AsString()),
// We set the SDK name as Beyla, so we can distinguish beyla generated metrics from other SDKs
semconv.TelemetrySDKNameKey.String("beyla"),
semconv.TelemetrySDKVersion(buildinfo.Version),
semconv.HostID(hostID),
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/internal/pipe/instrumenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func TestBasicPipeline(t *testing.T) {
event := testutil.ReadChannel(t, tc.Records(), testTimeout)
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
delete(event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.MetricRecord{
Name: "http.server.request.duration",
Unit: "s",
Expand Down Expand Up @@ -303,6 +306,8 @@ func TestRouteConsolidation(t *testing.T) {
for _, event := range events {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
delete(event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
}
assert.Equal(t, collector.MetricRecord{
Name: "http.server.request.duration",
Expand Down Expand Up @@ -415,6 +420,9 @@ func TestGRPCPipeline(t *testing.T) {
event := testutil.ReadChannel(t, tc.Records(), testTimeout)
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
delete(event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.MetricRecord{
Name: "rpc.server.duration",
Unit: "s",
Expand Down Expand Up @@ -509,6 +517,9 @@ func TestBasicPipelineInfo(t *testing.T) {
event := testutil.ReadChannel(t, tc.Records(), testTimeout)
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
delete(event.ResourceAttributes, string(semconv.ServiceInstanceIDKey))
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.MetricRecord{
Name: "http.server.request.duration",
Unit: "s",
Expand Down Expand Up @@ -688,6 +699,9 @@ func getHostname() string {
}

func matchTraceEvent(t require.TestingT, name string, event collector.TraceRecord) {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.NotEmpty(t, event.Attributes["span_id"])
assert.Equal(t, collector.TraceRecord{
Name: name,
Expand Down Expand Up @@ -716,6 +730,9 @@ func matchTraceEvent(t require.TestingT, name string, event collector.TraceRecor
}

func matchInnerTraceEvent(t require.TestingT, name string, event collector.TraceRecord) {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.NotEmpty(t, event.Attributes["span_id"])
assert.Equal(t, collector.TraceRecord{
Name: name,
Expand All @@ -737,6 +754,9 @@ func matchInnerTraceEvent(t require.TestingT, name string, event collector.Trace
}

func matchGRPCTraceEvent(t *testing.T, name string, event collector.TraceRecord) {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.TraceRecord{
Name: name,
Attributes: map[string]string{
Expand All @@ -762,6 +782,9 @@ func matchGRPCTraceEvent(t *testing.T, name string, event collector.TraceRecord)
}

func matchInnerGRPCTraceEvent(t *testing.T, name string, event collector.TraceRecord) {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.TraceRecord{
Name: name,
Attributes: map[string]string{
Expand Down Expand Up @@ -809,6 +832,9 @@ func newHTTPInfo(method, path, peer string, status int) []request.Span {
}

func matchInfoEvent(t *testing.T, name string, event collector.TraceRecord) {
assert.NotEmpty(t, event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))
delete(event.ResourceAttributes, string(semconv.TelemetrySDKVersionKey))

assert.Equal(t, collector.TraceRecord{
Name: name,
Attributes: map[string]string{
Expand Down

0 comments on commit 05851de

Please sign in to comment.