Skip to content

Commit

Permalink
Add host ID reporting to application metrics (#1042)
Browse files Browse the repository at this point in the history
* aws detector

* gcp detector

* all detectors. Still not integrated

* combined host ID fetcher

* first candidate

* host-id but hostname should be the K8s node name

* some tests

* Working kube node machine id implementation

* host ID in otel network metrics

* target info in prom app metrics

* integration tests

* removed wrong nolint comment

* more accurate description of FetchHostID

* Fix hostIDregex in integration tests
  • Loading branch information
mariomac authored Jul 22, 2024
1 parent 9a5f90e commit 99e4b40
Show file tree
Hide file tree
Showing 248 changed files with 86,223 additions and 45 deletions.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ require (
go.opentelemetry.io/collector/exporter/otlpexporter v0.104.0
go.opentelemetry.io/collector/exporter/otlphttpexporter v0.104.0
go.opentelemetry.io/collector/pdata v1.11.0
go.opentelemetry.io/contrib/detectors/aws/ec2 v1.28.0
go.opentelemetry.io/contrib/detectors/aws/eks v1.28.0
go.opentelemetry.io/contrib/detectors/azure/azurevm v0.0.1
go.opentelemetry.io/contrib/detectors/gcp v1.28.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0
Expand Down Expand Up @@ -76,6 +79,9 @@ replace go.opentelemetry.io/otel/sdk => github.com/grafana/opentelemetry-go/sdk
replace go.opentelemetry.io/otel/sdk/metric => github.com/grafana/opentelemetry-go/sdk/metric v1.28.0-grafana.2

require (
cloud.google.com/go/compute/metadata v0.4.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.0 // indirect
github.com/aws/aws-sdk-go v1.54.13 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand Down Expand Up @@ -108,6 +114,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
cloud.google.com/go/compute/metadata v0.4.0 h1:vHzJCWaM4g8XIcm8kopr3XmDA4Gy/lblD3EhhSux05c=
cloud.google.com/go/compute/metadata v0.4.0/go.mod h1:SIQh1Kkb4ZJ8zJ874fqVkslA29PRXuleyj6vOzlbK7M=
github.com/AlessandroPomponio/go-gibberish v0.0.0-20191004143433-a2d4156f0396 h1:cKIHT8I2mrmw/VgdyNeACP/AvetK8AgGsiRfOC3ZjmQ=
github.com/AlessandroPomponio/go-gibberish v0.0.0-20191004143433-a2d4156f0396/go.mod h1:2VCDG9kHYQ5vfYUqeoB7foVlcvIvB7rp9LxTELLD1qU=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.0 h1:N4xzkSD2BkRwEZSPf3C2eUZxjS5trpo4gOwRh8mu+BA=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.0/go.mod h1:p2puVVSKjQ84Qb1gzw2XHLs34WQyHTYFZLaVxypAFYs=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.54.13 h1:zpCuiG+/mFdDY/klKJvmSioAZWk45F4rLGq0JWVAAzk=
github.com/aws/aws-sdk-go v1.54.13/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down Expand Up @@ -118,6 +124,10 @@ github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyf
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down Expand Up @@ -291,8 +301,14 @@ go.opentelemetry.io/collector/receiver v0.104.0 h1:URL1ExkYYd+qbndm7CdGvI2mxzsv/
go.opentelemetry.io/collector/receiver v0.104.0/go.mod h1:+enTCZQLf6dRRANWvykXEzrlRw2JDppXJtoYWd/Dd54=
go.opentelemetry.io/contrib/config v0.7.0 h1:b1rK5tGTuhhPirJiMxOcyQfZs76j2VapY6ODn3b2Dbs=
go.opentelemetry.io/contrib/config v0.7.0/go.mod h1:8tdiFd8N5etOi3XzBmAoMxplEzI3TcL8dU5rM5/xcOQ=
go.opentelemetry.io/contrib/detectors/aws/ec2 v1.28.0 h1:d+y/wygENfwEbVpo7c3A9GfnMhoTiepQcthQSh+Mc9g=
go.opentelemetry.io/contrib/detectors/aws/ec2 v1.28.0/go.mod h1:gxGqapN+BNTBkKvKZFQJ1mfhQss7suB5gDmPwzJJWhQ=
go.opentelemetry.io/contrib/detectors/aws/eks v1.28.0 h1:446exEE2fdXqNttY+oHB54NMGXRAmQBaMz2fXkL77bc=
go.opentelemetry.io/contrib/detectors/aws/eks v1.28.0/go.mod h1:L2UOyaTFvypCAHW69TwGnce7YgKhSI9n8kAzQjyNbJk=
go.opentelemetry.io/contrib/detectors/azure/azurevm v0.0.1 h1:hgKJ88bL5cTomIlP7VYxsG4HfYeRp3U2tfcpZr0B0yY=
go.opentelemetry.io/contrib/detectors/azure/azurevm v0.0.1/go.mod h1:nmQyKaRlFYOboU/JGyRb1/9eLpuKYmTFd+rDjrIZTKk=
go.opentelemetry.io/contrib/detectors/gcp v1.28.0 h1:eAaOyCwPqwAG7INWn0JTDD3KFR4qbSlhh0YCuFOmmDE=
go.opentelemetry.io/contrib/detectors/gcp v1.28.0/go.mod h1:9BIqH22qyHWAiZxQh0whuJygro59z+nbMVuc7ciiGug=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 h1:vS1Ao/R55RNV4O7TA2Qopok8yN+X0LIP6RVWLFkprck=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0/go.mod h1:BMsdeOxN04K0L5FNUBfjFdvwWGNe/rkmSwH4Aelu/X0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
Expand Down
6 changes: 4 additions & 2 deletions pkg/components/beyla.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// RunBeyla in the foreground process. This is a blocking function and won't exit
// until both the AppO11y and NetO11y components end
func RunBeyla(ctx context.Context, cfg *beyla.Config) error {
ctxInfo := buildCommonContextInfo(cfg)
ctxInfo := buildCommonContextInfo(ctx, cfg)

wg := sync.WaitGroup{}
app := cfg.Enabled(beyla.FeatureAppO11y)
Expand Down Expand Up @@ -102,7 +102,7 @@ func mustSkip(cfg *beyla.Config) string {
// BuildContextInfo populates some globally shared components and properties
// from the user-provided configuration
func buildCommonContextInfo(
config *beyla.Config,
ctx context.Context, config *beyla.Config,
) *global.ContextInfo {
promMgr := &connector.PrometheusManager{}
ctxInfo := &global.ContextInfo{
Expand Down Expand Up @@ -131,6 +131,8 @@ func buildCommonContextInfo(

attributeGroups(config, ctxInfo)

ctxInfo.FetchHostID(ctx)

return ctxInfo
}

Expand Down
13 changes: 10 additions & 3 deletions pkg/export/alloy/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ import (
"github.com/grafana/beyla/pkg/beyla"
"github.com/grafana/beyla/pkg/export/attributes"
"github.com/grafana/beyla/pkg/export/otel"
"github.com/grafana/beyla/pkg/internal/pipe/global"
"github.com/grafana/beyla/pkg/internal/request"
)

// TracesReceiver creates a terminal node that consumes request.Spans and sends OpenTelemetry traces to the configured consumers.
func TracesReceiver(ctx context.Context, cfg *beyla.TracesReceiverConfig, userAttribSelection attributes.Selection) pipe.FinalProvider[[]request.Span] {
return (&tracesReceiver{ctx: ctx, cfg: cfg, attributes: userAttribSelection}).provideLoop
func TracesReceiver(
ctx context.Context,
ctxInfo *global.ContextInfo,
cfg *beyla.TracesReceiverConfig,
userAttribSelection attributes.Selection,
) pipe.FinalProvider[[]request.Span] {
return (&tracesReceiver{ctx: ctx, cfg: cfg, attributes: userAttribSelection, hostID: ctxInfo.HostID}).provideLoop
}

type tracesReceiver struct {
ctx context.Context
cfg *beyla.TracesReceiverConfig
attributes attributes.Selection
hostID string
}

func (tr *tracesReceiver) provideLoop() (pipe.FinalFunc[[]request.Span], error) {
Expand All @@ -42,7 +49,7 @@ func (tr *tracesReceiver) provideLoop() (pipe.FinalFunc[[]request.Span], error)
}

for _, tc := range tr.cfg.Traces {
traces := otel.GenerateTraces(span, traceAttrs)
traces := otel.GenerateTraces(span, tr.hostID, traceAttrs)
err := tc.ConsumeTraces(tr.ctx, traces)
if err != nil {
slog.Error("error sending trace to consumer", "error", err)
Expand Down
7 changes: 4 additions & 3 deletions pkg/export/otel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ var DefaultBuckets = Buckets{
RequestSizeHistogram: []float64{0, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192},
}

func getAppResourceAttrs(service *svc.ID) []attribute.KeyValue {
return append(getResourceAttrs(service),
func getAppResourceAttrs(hostID string, service *svc.ID) []attribute.KeyValue {
return append(getResourceAttrs(hostID, service),
semconv.ServiceInstanceID(service.Instance),
)
}

func getResourceAttrs(service *svc.ID) []attribute.KeyValue {
func getResourceAttrs(hostID string, service *svc.ID) []attribute.KeyValue {
attrs := []attribute.KeyValue{
semconv.ServiceName(service.Name),
// SpanMetrics requires an extra attribute besides service name
Expand All @@ -76,6 +76,7 @@ func getResourceAttrs(service *svc.ID) []attribute.KeyValue {
// We set the SDK name as Beyla, so we can distinguish beyla generated metrics from other SDKs
semconv.TelemetrySDKNameKey.String("beyla"),
semconv.HostName(service.HostName),
semconv.HostID(hostID),
}

if service.Namespace != "" {
Expand Down
6 changes: 5 additions & 1 deletion pkg/export/otel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (m *MetricsConfig) Enabled() bool {
type MetricsReporter struct {
ctx context.Context
cfg *MetricsConfig
hostID string
attributes *attributes.AttrSelector
exporter metric.Exporter
reporters ReporterPool[*svc.ID, *Metrics]
Expand Down Expand Up @@ -250,6 +251,7 @@ func newMetricsReporter(
cfg: cfg,
is: is,
attributes: attribProvider,
hostID: ctxInfo.HostID,
}
// initialize attribute getters
if is.HTTPEnabled() {
Expand Down Expand Up @@ -522,7 +524,7 @@ func (mr *MetricsReporter) setupGraphMeters(m *Metrics, meter instrument.Meter)
func (mr *MetricsReporter) newMetricSet(service *svc.ID) (*Metrics, error) {
mlog := mlog().With("service", service)
mlog.Debug("creating new Metrics reporter")
resources := resource.NewWithAttributes(semconv.SchemaURL, getAppResourceAttrs(service)...)
resources := resource.NewWithAttributes(semconv.SchemaURL, getAppResourceAttrs(mr.hostID, service)...)

opts := []metric.Option{
metric.WithResource(resources),
Expand Down Expand Up @@ -691,6 +693,7 @@ func (mr *MetricsReporter) metricResourceAttributes(service *svc.ID) attribute.S
semconv.TelemetrySDKLanguageKey.String(service.SDKLanguage.String()),
semconv.TelemetrySDKNameKey.String("beyla"),
request.SourceMetric("beyla"),
semconv.HostID(mr.hostID),
}
for k, v := range service.Metadata {
attrs = append(attrs, k.OTEL().String(v))
Expand All @@ -708,6 +711,7 @@ func (mr *MetricsReporter) spanMetricAttributes(span *request.Span) attribute.Se
request.SpanNameMetric(TraceName(span)),
request.StatusCodeMetric(int(request.SpanStatusCode(span))),
request.SourceMetric("beyla"),
semconv.HostID(mr.hostID),
}

return attribute.NewSet(attrs...)
Expand Down
5 changes: 3 additions & 2 deletions pkg/export/otel/metrics_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func nmlog() *slog.Logger {
return slog.With("component", "otel.NetworkMetricsExporter")
}

func newResource() *resource.Resource {
func newResource(hostID string) *resource.Resource {
attrs := []attribute.KeyValue{
semconv.ServiceName("beyla-network-flows"),
semconv.ServiceInstanceID(uuid.New().String()),
Expand All @@ -46,6 +46,7 @@ func newResource() *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.HostID(hostID),
}

return resource.NewWithAttributes(semconv.SchemaURL, attrs...)
Expand Down Expand Up @@ -87,7 +88,7 @@ func newMetricsExporter(ctx context.Context, ctxInfo *global.ContextInfo, cfg *N
return nil, err
}

provider, err := newMeterProvider(newResource(), &exporter, cfg.Metrics.Interval)
provider, err := newMeterProvider(newResource(ctxInfo.HostID), &exporter, cfg.Metrics.Interval)

if err != nil {
log.Error("", "error", err)
Expand Down
10 changes: 6 additions & 4 deletions pkg/export/otel/metrics_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type procMetricsExporter struct {
cfg *ProcMetricsConfig
clock *expire.CachedClock

hostID string

exporter metric.Exporter
reporters ReporterPool[*process.ID, *procMetrics]

Expand Down Expand Up @@ -136,6 +138,7 @@ func newProcMetricsExporter(
log: log,
ctx: ctx,
cfg: cfg,
hostID: ctxInfo.HostID,
clock: expire.NewCachedClock(timeNow),
attrCPUTime: attrCPUTime,
attrCPUUtil: attrCPUUtil,
Expand Down Expand Up @@ -188,10 +191,9 @@ func newProcMetricsExporter(
return mr.Do, nil
}

func getProcessResourceAttrs(procID *process.ID) []attribute.KeyValue {
func getProcessResourceAttrs(hostID string, procID *process.ID) []attribute.KeyValue {
return append(
getAppResourceAttrs(procID.Service),
semconv.ServiceInstanceID(string(procID.UID)),
getAppResourceAttrs(hostID, procID.Service),
attr2.ProcCommand.OTEL().String(procID.Command),
attr2.ProcOwner.OTEL().String(procID.User),
attr2.ProcParentPid.OTEL().String(strconv.Itoa(int(procID.ParentProcessID))),
Expand All @@ -206,7 +208,7 @@ func getProcessResourceAttrs(procID *process.ID) []attribute.KeyValue {
func (me *procMetricsExporter) newMetricSet(procID *process.ID) (*procMetrics, error) {
log := me.log.With("service", procID.Service, "processID", procID.UID)
log.Debug("creating new Metrics exporter")
resources := resource.NewWithAttributes(semconv.SchemaURL, getProcessResourceAttrs(procID)...)
resources := resource.NewWithAttributes(semconv.SchemaURL, getProcessResourceAttrs(me.hostID, procID)...)
opts := []metric.Option{
metric.WithResource(resources),
metric.WithReader(metric.NewPeriodicReader(me.exporter,
Expand Down
6 changes: 3 additions & 3 deletions pkg/export/otel/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (tr *tracesOTELReceiver) provideLoop() (pipe.FinalFunc[[]request.Span], err
if span.IgnoreSpan == request.IgnoreTraces || !tr.acceptSpan(span) {
continue
}
traces := GenerateTraces(span, traceAttrs)
traces := GenerateTraces(span, tr.ctxInfo.HostID, traceAttrs)
err := exp.ConsumeTraces(tr.ctx, traces)
if err != nil {
slog.Error("error sending trace to consumer", "error", err)
Expand Down Expand Up @@ -363,14 +363,14 @@ func getRetrySettings(cfg TracesConfig) configretry.BackOffConfig {
}

// GenerateTraces creates a ptrace.Traces from a request.Span
func GenerateTraces(span *request.Span, userAttrs map[attr.Name]struct{}) ptrace.Traces {
func GenerateTraces(span *request.Span, hostID string, userAttrs map[attr.Name]struct{}) ptrace.Traces {
t := span.Timings()
start := spanStartTime(t)
hasSubSpans := t.Start.After(start)
traces := ptrace.NewTraces()
rs := traces.ResourceSpans().AppendEmpty()
ss := rs.ScopeSpans().AppendEmpty()
resourceAttrs := attrsToMap(getAppResourceAttrs(&span.ServiceID))
resourceAttrs := attrsToMap(getAppResourceAttrs(hostID, &span.ServiceID))
resourceAttrs.PutStr(string(semconv.OTelLibraryNameKey), reporterName)
resourceAttrs.CopyTo(rs.Resource().Attributes())

Expand Down
22 changes: 11 additions & 11 deletions pkg/export/otel/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestGenerateTraces(t *testing.T) {
TraceID: traceID,
SpanID: spanID,
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestGenerateTraces(t *testing.T) {
SpanID: spanID,
TraceID: traceID,
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestGenerateTraces(t *testing.T) {
Route: "/test",
Status: 200,
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestGenerateTraces(t *testing.T) {
SpanID: spanID,
TraceID: traceID,
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -472,7 +472,7 @@ func TestGenerateTraces(t *testing.T) {
ParentSpanID: parentSpanID,
TraceID: traceID,
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -492,7 +492,7 @@ func TestGenerateTraces(t *testing.T) {
Method: "GET",
Route: "/test",
}
traces := GenerateTraces(span, map[attr.Name]struct{}{})
traces := GenerateTraces(span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -508,7 +508,7 @@ func TestGenerateTraces(t *testing.T) {
func TestGenerateTracesAttributes(t *testing.T) {
t.Run("test SQL trace generation, no statement", func(t *testing.T) {
span := makeSQLRequestSpan("SELECT password FROM credentials WHERE username=\"bill\"")
traces := GenerateTraces(&span, map[attr.Name]struct{}{})
traces := GenerateTraces(&span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -529,7 +529,7 @@ func TestGenerateTracesAttributes(t *testing.T) {

t.Run("test SQL trace generation, unknown attribute", func(t *testing.T) {
span := makeSQLRequestSpan("SELECT password FROM credentials WHERE username=\"bill\"")
traces := GenerateTraces(&span, map[attr.Name]struct{}{"db.operation.name": {}})
traces := GenerateTraces(&span, "host-id", map[attr.Name]struct{}{"db.operation.name": {}})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -550,7 +550,7 @@ func TestGenerateTracesAttributes(t *testing.T) {

t.Run("test SQL trace generation, unknown attribute", func(t *testing.T) {
span := makeSQLRequestSpan("SELECT password FROM credentials WHERE username=\"bill\"")
traces := GenerateTraces(&span, map[attr.Name]struct{}{attr.DBQueryText: {}})
traces := GenerateTraces(&span, "host-id", map[attr.Name]struct{}{attr.DBQueryText: {}})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand All @@ -570,7 +570,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
})
t.Run("test Kafka trace generation", func(t *testing.T) {
span := request.Span{Type: request.EventTypeKafkaClient, Method: "process", Path: "important-topic", OtherNamespace: "test"}
traces := GenerateTraces(&span, map[attr.Name]struct{}{})
traces := GenerateTraces(&span, "host-id", map[attr.Name]struct{}{})

assert.Equal(t, 1, traces.ResourceSpans().Len())
assert.Equal(t, 1, traces.ResourceSpans().At(0).ScopeSpans().Len())
Expand Down Expand Up @@ -1143,7 +1143,7 @@ func generateTracesForSpans(t *testing.T, tr *tracesOTELReceiver, spans []reques
if span.IgnoreSpan == request.IgnoreTraces || !tr.acceptSpan(span) {
continue
}
res = append(res, GenerateTraces(span, traceAttrs))
res = append(res, GenerateTraces(span, "host-id", traceAttrs))
}

return res
Expand Down
Loading

0 comments on commit 99e4b40

Please sign in to comment.