Skip to content

Commit

Permalink
Merge branch 'main' into y/tsp-tick-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yvrhdn authored Jan 17, 2025
2 parents 815263f + 25912dc commit 8675fc7
Show file tree
Hide file tree
Showing 24 changed files with 336 additions and 42 deletions.
28 changes: 28 additions & 0 deletions .chloggen/deprecate_githubgen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: githubgen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate githubgen in this repository

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [37294]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
githubgen has moved to opentelemetry-go-build-tools. Please change your scripts to use this new location.
# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/ibraheem_add-gate-for-operation-name-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add a feature gate datadog.EnableOperationAndResourceNameV2. Enabling this gate modifies the logic for computing operation and resource names from OTLP spans to produce shorter, more readable names and improve alignment with OpenTelemetry specifications."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36419]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/prometheusremotewrite-reallow-multiple-workers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: prometheusremotewriteexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Re allows the configuration of multiple workers

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36134]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 0 additions & 1 deletion .github/ALLOWLIST
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ exporter/kineticaexporter/
exporter/opensearchexporter/
extension/observer/ecstaskobserver/
extension/storage/filestorage/
receiver/jmxreceiver/
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ receiver/huaweicloudcesreceiver/ @open-telemetry
receiver/iisreceiver/ @open-telemetry/collector-contrib-approvers @Mrod1598 @pjanotti
receiver/influxdbreceiver/ @open-telemetry/collector-contrib-approvers @jacobmarble
receiver/jaegerreceiver/ @open-telemetry/collector-contrib-approvers @yurishkuro
receiver/jmxreceiver/ @open-telemetry/collector-contrib-approvers @atoulme
receiver/journaldreceiver/ @open-telemetry/collector-contrib-approvers @sumo-drosiek @djaglowski
receiver/k8sclusterreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax @TylerHelmuth @povilasv @ChrsMark
receiver/k8seventsreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax @TylerHelmuth @ChrsMark
Expand Down Expand Up @@ -324,8 +325,7 @@ reports/distributions/k8s.yaml @open-telemetry/collector-contrib-approvers

## UNMAINTAINED components

exporter/kineticaexporter/ @open-telemetry/collector-contrib-approvers
exporter/opensearchexporter/ @open-telemetry/collector-contrib-approvers
extension/observer/ecstaskobserver/ @open-telemetry/collector-contrib-approvers
extension/storage/filestorage/ @open-telemetry/collector-contrib-approvers
receiver/jmxreceiver/ @open-telemetry/collector-contrib-approvers
exporter/kineticaexporter/ @open-telemetry/collector-contrib-approvers
exporter/opensearchexporter/ @open-telemetry/collector-contrib-approvers
extension/observer/ecstaskobserver/ @open-telemetry/collector-contrib-approvers
extension/storage/filestorage/ @open-telemetry/collector-contrib-approvers
4 changes: 4 additions & 0 deletions cmd/githubgen/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:warn: This executable has moved to [opentelemetry-go-build-tools](Deprecated: use https://github.com/open-telemetry/opentelemetry-go-build-tools/tree/main/githubgen).

This code is deprecated and will be removed soon. See https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/37294.

# githubgen

This executable is used to generate the `.github/CODEOWNERS` and `.github/ALLOWLIST` files.
Expand Down
1 change: 1 addition & 0 deletions cmd/githubgen/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Deprecated: use https://github.com/open-telemetry/opentelemetry-go-build-tools/tree/main/githubgen
module github.com/open-telemetry/opentelemetry-collector-contrib/cmd/githubgen

go 1.22.0
Expand Down
1 change: 1 addition & 0 deletions cmd/githubgen/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Deprecated: use https://github.com/open-telemetry/opentelemetry-go-build-tools/tree/main/githubgen
package main

import (
Expand Down
5 changes: 5 additions & 0 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func getTraceAgentCfg(logger *zap.Logger, cfg TracesConfig, attributesTranslator
if datadog.ReceiveResourceSpansV2FeatureGate.IsEnabled() {
acfg.Features["enable_receive_resource_spans_v2"] = struct{}{}
}
if datadog.OperationAndResourceNameV2FeatureGate.IsEnabled() {
acfg.Features["enable_operation_and_resource_name_logic_v2"] = struct{}{}
} else {
logger.Info("Please enable feature gate datadog.EnableOperationAndResourceNameV2 for improved operation and resource name logic. This feature will be enabled by default in the future - if you have Datadog monitors or alerts set on operation/resource names, you may need to migrate them to the new convention.")
}
if v := cfg.BucketInterval; v > 0 {
acfg.BucketInterval = v
}
Expand Down
20 changes: 20 additions & 0 deletions connector/datadogconnector/connector_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/ptrace"
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
"go.uber.org/zap"
Expand Down Expand Up @@ -130,6 +131,18 @@ var (
)

func TestMeasuredAndClientKindNative(t *testing.T) {
t.Run("OperationAndResourceNameV1", func(t *testing.T) {
testMeasuredAndClientKindNative(t, false)
})
t.Run("OperationAndResourceNameV2", func(t *testing.T) {
testMeasuredAndClientKindNative(t, true)
})
}

func testMeasuredAndClientKindNative(t *testing.T, enableOperationAndResourceNameV2 bool) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", enableOperationAndResourceNameV2); err != nil {
t.Fatal(err)
}
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.Traces.ComputeTopLevelBySpanKind = true
connector, metricsSink := creteConnectorNativeWithCfg(t, cfg)
Expand Down Expand Up @@ -240,6 +253,13 @@ func TestMeasuredAndClientKindNative(t *testing.T) {
IsTraceRoot: pb.Trilean_TRUE,
},
}

if enableOperationAndResourceNameV2 {
expected[0].Name = "Internal"
expected[1].Name = "client.request"
expected[2].Name = "server.request"
}

if diff := cmp.Diff(
cgss,
expected,
Expand Down
60 changes: 60 additions & 0 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,66 @@ func testReceiveResourceSpansV2(t *testing.T, enableReceiveResourceSpansV2 bool)
}
}

func TestOperationAndResourceNameV2(t *testing.T) {
t.Run("OperationAndResourceNameV1", func(t *testing.T) {
testOperationAndResourceNameV2(t, false)
})
t.Run("OperationAndResourceNameV2", func(t *testing.T) {
testOperationAndResourceNameV2(t, true)
})
}

func testOperationAndResourceNameV2(t *testing.T, enableOperationAndResourceNameV2 bool) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", enableOperationAndResourceNameV2); err != nil {
t.Fatal(err)
}
connector, metricsSink := creteConnector(t)
err := connector.Start(context.Background(), componenttest.NewNopHost())
if err != nil {
t.Errorf("Error starting connector: %v", err)
return
}
defer func() {
_ = connector.Shutdown(context.Background())
}()

trace := generateTrace()
rspan := trace.ResourceSpans().At(0)
rspan.Resource().Attributes().PutStr("deployment.environment.name", "new_env")
rspan.ScopeSpans().At(0).Spans().At(0).SetKind(ptrace.SpanKindServer)

err = connector.ConsumeTraces(context.Background(), trace)
assert.NoError(t, err)

for {
if len(metricsSink.AllMetrics()) > 0 {
break
}
time.Sleep(100 * time.Millisecond)
}

// check if the container tags are added to the metrics
metrics := metricsSink.AllMetrics()
assert.Len(t, metrics, 1)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}

err = proto.Unmarshal(msg, sp)
require.NoError(t, err)

gotName := sp.Stats[0].Stats[0].Stats[0].Name
if enableOperationAndResourceNameV2 {
assert.Equal(t, "server.request", gotName)
} else {
assert.Equal(t, "opentelemetry.server", gotName)
}
}

func newTranslatorWithStatsChannel(t *testing.T, logger *zap.Logger, ch chan []byte) *otlpmetrics.Translator {
options := []otlpmetrics.TranslatorOption{
otlpmetrics.WithHistogramMode(otlpmetrics.HistogramModeDistributions),
Expand Down
5 changes: 5 additions & 0 deletions exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func newTraceAgentConfig(ctx context.Context, params exporter.Settings, cfg *Con
return clientutil.NewHTTPClient(cfg.ClientConfig)
}
}
if datadog.OperationAndResourceNameV2FeatureGate.IsEnabled() {
acfg.Features["enable_operation_and_resource_name_logic_v2"] = struct{}{}
} else {
params.Logger.Info("Please enable feature gate datadog.EnableOperationAndResourceNameV2 for improved operation and resource name logic. This feature will be enabled by default in the future - if you have Datadog monitors or alerts set on operation/resource names, you may need to migrate them to the new convention.")
}
if v := cfg.Traces.GetFlushInterval(); v > 0 {
acfg.TraceWriter.FlushPeriodSeconds = v
}
Expand Down
68 changes: 53 additions & 15 deletions exporter/datadogexporter/traces_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func testTracesSource(t *testing.T, enableReceiveResourceSpansV2 bool) {
} {
t.Run("", func(t *testing.T) {
ctx := context.Background()
err = exporter.ConsumeTraces(ctx, simpleTracesWithResAttributes(tt.attrs))
err = exporter.ConsumeTraces(ctx, simpleTraces(tt.attrs, nil, ptrace.SpanKindInternal))
assert.NoError(err)
timeout := time.After(time.Second)
select {
Expand Down Expand Up @@ -307,7 +307,7 @@ func testTraceExporter(t *testing.T, enableReceiveResourceSpansV2 bool) {
assert.NoError(t, err)

ctx := context.Background()
err = exporter.ConsumeTraces(ctx, simpleTraces())
err = exporter.ConsumeTraces(ctx, simpleTraces(nil, nil, ptrace.SpanKindInternal))
assert.NoError(t, err)
timeout := time.After(2 * time.Second)
select {
Expand Down Expand Up @@ -428,7 +428,7 @@ func testPushTraceDataNewEnvConvention(t *testing.T, enableReceiveResourceSpansV
exp, err := f.CreateTraces(context.Background(), params, cfg)
assert.NoError(t, err)

err = exp.ConsumeTraces(context.Background(), simpleTracesWithResAttributes(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}))
err = exp.ConsumeTraces(context.Background(), simpleTraces(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}, nil, ptrace.SpanKindInternal))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
Expand All @@ -443,6 +443,51 @@ func testPushTraceDataNewEnvConvention(t *testing.T, enableReceiveResourceSpansV
assert.Equal(t, "new_env", traces.TracerPayloads[0].GetEnv())
}

func TestPushTraceData_OperationAndResourceNameV2(t *testing.T) {
err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", true)
if err != nil {
t.Fatal(err)
}
tracesRec := &testutil.HTTPRequestRecorderWithChan{Pattern: testutil.TraceEndpoint, ReqChan: make(chan []byte)}
server := testutil.DatadogServerMock(tracesRec.HandlerFunc)
defer server.Close()
cfg := &Config{
API: APIConfig{
Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
TagsConfig: TagsConfig{
Hostname: "test-host",
},
Metrics: MetricsConfig{
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
},
Traces: TracesConfig{
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
},
}
cfg.Traces.SetFlushInterval(0.1)

params := exportertest.NewNopSettings()
f := NewFactory()
exp, err := f.CreateTraces(context.Background(), params, cfg)
assert.NoError(t, err)

err = exp.ConsumeTraces(context.Background(), simpleTraces(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}, nil, ptrace.SpanKindServer))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
buf := bytes.NewBuffer(reqBytes)
reader, err := gzip.NewReader(buf)
require.NoError(t, err)
slurp, err := io.ReadAll(reader)
require.NoError(t, err)
var traces pb.AgentPayload
require.NoError(t, proto.Unmarshal(slurp, &traces))
assert.Len(t, traces.TracerPayloads, 1)
assert.Equal(t, "new_env", traces.TracerPayloads[0].GetEnv())
assert.Equal(t, "server.request", traces.TracerPayloads[0].Chunks[0].Spans[0].Name)
}

func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *testing.T) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableReceiveResourceSpansV2", true); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -480,7 +525,7 @@ func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *t
"service.name": "do-not-use",
"service.version": "do-not-use",
}
err = exp.ConsumeTraces(context.Background(), simpleTracesWithResAndSpanAttributes(nil, sattr))
err = exp.ConsumeTraces(context.Background(), simpleTraces(nil, sattr, ptrace.SpanKindInternal))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
Expand All @@ -501,24 +546,17 @@ func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *t
assert.Empty(t, span.Meta["version"])
}

func simpleTraces() ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, nil, nil)
}

func simpleTracesWithResAttributes(rattrs map[string]any) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, nil)
}

func simpleTracesWithResAndSpanAttributes(rattrs map[string]any, sattrs map[string]any) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, sattrs)
func simpleTraces(rattrs map[string]any, sattrs map[string]any, kind ptrace.SpanKind) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, sattrs, kind)
}

func genTraces(traceID pcommon.TraceID, rattrs map[string]any, sattrs map[string]any) ptrace.Traces {
func genTraces(traceID pcommon.TraceID, rattrs map[string]any, sattrs map[string]any, kind ptrace.SpanKind) ptrace.Traces {
traces := ptrace.NewTraces()
rspans := traces.ResourceSpans().AppendEmpty()
span := rspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(traceID)
span.SetSpanID([8]byte{0, 0, 0, 0, 1, 2, 3, 4})
span.SetKind(kind)
if rattrs == nil {
return traces
}
Expand Down
Loading

0 comments on commit 8675fc7

Please sign in to comment.