Skip to content

Commit

Permalink
Fix trace and logging user agent, and add tests (#714)
Browse files Browse the repository at this point in the history
* prepend user agent to avoid overwriting provided options

* cloudmock records user agent header

* add user agent to text fixture protos

* update fixtures with user agent

* check user agent in integration tests

* set {{version}} in logging exporter

* add fixture case for custom user agent
  • Loading branch information
dashpole committed Aug 23, 2023
1 parent 858780d commit 92fd371
Show file tree
Hide file tree
Showing 68 changed files with 3,858 additions and 89 deletions.
3 changes: 3 additions & 0 deletions exporter/collector/integrationtest/cmd/recordfixtures/main.go
Expand Up @@ -97,6 +97,7 @@ func (fr fixtureRecorder) recordTraces(ctx context.Context, t *FakeTesting, star
require.NoError(t, err)
fixture := &protos.TraceExpectFixture{
BatchWriteSpansRequest: testServer.CreateBatchWriteSpansRequests(),
UserAgent: testServer.UserAgent(),
}
test.SaveRecordedTraceFixtures(t, fixture)
}()
Expand Down Expand Up @@ -128,6 +129,7 @@ func (fr fixtureRecorder) recordLogs(ctx context.Context, t *FakeTesting, timest
require.NoError(t, err)
fixture := &protos.LogExpectFixture{
WriteLogEntriesRequests: testServer.CreateWriteLogEntriesRequests(),
UserAgent: testServer.UserAgent(),
}
test.SaveRecordedLogFixtures(t, fixture)
}()
Expand Down Expand Up @@ -172,6 +174,7 @@ func (fr fixtureRecorder) recordMetrics(ctx context.Context, t *FakeTesting, sta
CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(),
CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(),
SelfObservabilityMetrics: selfObsMetrics,
UserAgent: testServer.UserAgent(),
}
test.SaveRecordedMetricFixtures(t, fixture)
}()
Expand Down
1 change: 1 addition & 0 deletions exporter/collector/integrationtest/inmemoryocexporter.go
Expand Up @@ -188,6 +188,7 @@ func NewLogTestExporter(
ctx,
cfg,
logger,
"latest",
)
require.NoError(t, err)

Expand Down
Expand Up @@ -45,6 +45,7 @@ func createLogsExporter(
ctx,
cfg,
logger,
"latest",
)
exporter.ConfigureExporter(test.ConfigureLogsExporter)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions exporter/collector/integrationtest/logs_test.go
Expand Up @@ -75,6 +75,7 @@ func TestLogs(t *testing.T) {

fixture := &protos.LogExpectFixture{
WriteLogEntriesRequests: testServer.CreateWriteLogEntriesRequests(),
UserAgent: testServer.UserAgent(),
}
// sort the entries in each request
for listIndex := 0; listIndex < len(fixture.WriteLogEntriesRequests); listIndex++ {
Expand Down
3 changes: 3 additions & 0 deletions exporter/collector/integrationtest/metrics_test.go
Expand Up @@ -96,6 +96,7 @@ func TestCollectorMetrics(t *testing.T) {
CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(),
CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(),
SelfObservabilityMetrics: selfObsMetrics,
UserAgent: testServer.UserAgent(),
}
sort.Slice(fixture.CreateTimeSeriesRequests, func(i, j int) bool {
return fixture.CreateTimeSeriesRequests[i].Name < fixture.CreateTimeSeriesRequests[j].Name
Expand Down Expand Up @@ -183,6 +184,7 @@ func TestSDKMetrics(t *testing.T) {
apioption.WithEndpoint(testServer.Endpoint),
apioption.WithoutAuthentication(),
apioption.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
apioption.WithUserAgent("opentelemetry-collector-contrib latest"),
)},
test.MetricSDKExporterOptions...,
)
Expand Down Expand Up @@ -225,6 +227,7 @@ func TestSDKMetrics(t *testing.T) {
CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(),
CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(),
CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(),
UserAgent: testServer.UserAgent(),
// Do not test self-observability metrics with SDK exporters
}
sort.Slice(fixture.CreateTimeSeriesRequests, func(i, j int) bool {
Expand Down
84 changes: 57 additions & 27 deletions exporter/collector/integrationtest/protos/fixtures.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exporter/collector/integrationtest/protos/fixtures.proto
Expand Up @@ -25,6 +25,7 @@ message MetricExpectFixture {
repeated google.monitoring.v3.CreateMetricDescriptorRequest create_metric_descriptor_requests = 2;
repeated google.monitoring.v3.CreateTimeSeriesRequest create_service_time_series_requests = 3;
SelfObservabilityMetric self_observability_metrics = 4;
string user_agent = 5;
}

message SelfObservabilityMetric {
Expand All @@ -34,8 +35,10 @@ message SelfObservabilityMetric {

message LogExpectFixture {
repeated google.logging.v2.WriteLogEntriesRequest write_log_entries_requests = 1;
string user_agent = 2;
}

message TraceExpectFixture {
repeated google.tracing.v2.BatchWriteSpansRequest batch_write_spans_request = 1;
string user_agent = 2;
}
Expand Up @@ -88,4 +88,12 @@ var LogsTestCases = []TestCase{
MaxRequestSize: 550,
},
},
{
Name: "Logs custom user-agent",
OTLPInputFixturePath: "testdata/fixtures/logs/logs_span_trace_id.json",
ExpectFixturePath: "testdata/fixtures/logs/logs_user_agent_expected.json",
ConfigureCollector: func(cfg *collector.Config) {
cfg.UserAgent = "custom-user-agent {{version}}"
},
},
}
12 changes: 12 additions & 0 deletions exporter/collector/integrationtest/testcases/testcases_metrics.go
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"google.golang.org/api/option"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
Expand Down Expand Up @@ -317,6 +318,17 @@ var MetricsTestCases = []TestCase{
// SDK exporter does not support CreateServiceTimeSeries
SkipForSDK: true,
},
{
Name: "Custom User Agent",
OTLPInputFixturePath: "testdata/fixtures/metrics/counter.json",
ExpectFixturePath: "testdata/fixtures/metrics/counter_user_agent_expect.json",
ConfigureCollector: func(cfg *collector.Config) {
cfg.UserAgent = "custom-user-agent"
},
MetricSDKExporterOptions: []metric.Option{
metric.WithMonitoringClientOptions(option.WithUserAgent("custom-user-agent")),
},
},
// Tests for the GMP exporter
{
Name: "[GMP] prometheus receiver metrics",
Expand Down
10 changes: 10 additions & 0 deletions exporter/collector/integrationtest/testcases/testcases_traces.go
Expand Up @@ -14,10 +14,20 @@

package testcases

import "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"

var TracesTestCases = []TestCase{
{
Name: "Basic traces",
OTLPInputFixturePath: "testdata/fixtures/traces/traces_basic.json",
ExpectFixturePath: "testdata/fixtures/traces/traces_basic_expected.json",
},
{
Name: "Custom User Agent",
OTLPInputFixturePath: "testdata/fixtures/traces/traces_basic.json",
ExpectFixturePath: "testdata/fixtures/traces/traces_user_agent_expected.json",
ConfigureCollector: func(cfg *collector.Config) {
cfg.UserAgent = "custom-user-agent {{version}}"
},
},
}
Expand Up @@ -451,5 +451,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -406,5 +406,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -456,5 +456,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -178,5 +178,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -26,5 +26,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -179,5 +179,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -43,5 +43,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -776,5 +776,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -771,5 +771,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}
Expand Up @@ -127,5 +127,6 @@
],
"partialSuccess": true
}
]
],
"userAgent": "opentelemetry-collector-contrib latest grpc-go/1.57.0"
}

0 comments on commit 92fd371

Please sign in to comment.