Skip to content

Commit

Permalink
modify tests/todo
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraheemA committed Dec 20, 2024
1 parent 1ca3e82 commit a4940be
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions processor/datadogsemanticsprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func TestBasicTranslation(t *testing.T) {
name string
overrideIncomingDatadogFields bool
in []testutil.OTLPResourceSpan
metaOverride map[string]string
metricsOverride map[string]float64
fn func(*ptrace.Traces)
}{
{
Expand Down Expand Up @@ -245,6 +247,8 @@ func TestBasicTranslation(t *testing.T) {
{
name: "don't overrideIncomingDatadogFields",
overrideIncomingDatadogFields: false,
metaOverride: map[string]string{"env": "specified-env"},
metricsOverride: map[string]float64{semconv.AttributeHTTPStatusCode: 500.0},
in: []testutil.OTLPResourceSpan{
{
LibName: "libname",
Expand All @@ -261,17 +265,13 @@ func TestBasicTranslation(t *testing.T) {
ParentID: [8]byte{0, 0, 0, 0, 0, 0, 0, 1},
Kind: ptrace.SpanKindServer,
Attributes: map[string]interface{}{
"datadog.service": "specified-service",
"datadog.resource": "specified-resource",
"datadog.name": "specified-operation",
"datadog.trace_id": "123456789",
"datadog.span_id": "987654321",
"datadog.parent_id": "123456789",
"datadog.type": "specified-type",
// TODO: Update testutil.NewOTLPTracesRequest to support map[string]interface{},
// then update this test to override meta and metrics.
//"datadog.meta": map[string]interface{}{"env": "specified-env"},
//"datadog.metrics": map[string]interface{}{semconv.AttributeHTTPStatusCode: 500},
"datadog.service": "specified-service",
"datadog.resource": "specified-resource",
"datadog.name": "specified-operation",
"datadog.trace_id": "123456789",
"datadog.span_id": "987654321",
"datadog.parent_id": "123456789",
"datadog.type": "specified-type",
"operation.name": "test-operation",
semconv.AttributeHTTPStatusCode: 200,
},
Expand All @@ -296,14 +296,12 @@ func TestBasicTranslation(t *testing.T) {
require.Equal(t, "123456789", ddParentID.AsString())
ddType, _ := span.Attributes().Get("datadog.type")
require.Equal(t, "specified-type", ddType.AsString())
// TODO: Update testutil.NewOTLPTracesRequest to support map[string]interface{},
// then update this test to check the values of meta and metrics.
//meta, _ := span.Attributes().Get("datadog.meta")
//env, _ := meta.Map().Get("env")
//require.Equal(t, "specified-env", env.AsString())
//metrics, _ := span.Attributes().Get("datadog.metrics")
//statusCode, _ := metrics.Map().Get(semconv.AttributeHTTPStatusCode)
//require.Equal(t, 500.0, statusCode.Double())
meta, _ := span.Attributes().Get("datadog.meta")
env, _ := meta.Map().Get("env")
require.Equal(t, "specified-env", env.AsString())
metrics, _ := span.Attributes().Get("datadog.metrics")
statusCode, _ := metrics.Map().Get(semconv.AttributeHTTPStatusCode)
require.Equal(t, 500.0, statusCode.Double())
},
},
}
Expand All @@ -319,6 +317,22 @@ func TestBasicTranslation(t *testing.T) {

traces := testutil.NewOTLPTracesRequest(tt.in)

// TODO: Update testutil.NewOTLPTracesRequest to support map[string]interface{}, then update this test to
// specify meta and metrics along with other attributes instead of using separate fields.
sattr := traces.Traces().ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes()
if tt.metaOverride != nil {
meta := sattr.PutEmptyMap("datadog.meta")
for k, v := range tt.metaOverride {
meta.PutStr(k, v)
}
}
if tt.metricsOverride != nil {
metrics := sattr.PutEmptyMap("datadog.metrics")
for k, v := range tt.metricsOverride {
metrics.PutDouble(k, v)
}
}

m.testConsume(context.Background(),
traces.Traces(),
nil,
Expand Down

0 comments on commit a4940be

Please sign in to comment.