Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e

receiverPipelineType, metricsRDM, metricsProcessors := r.metricsProcessors(ctx)

return []otel.ReceiverPipeline{{
converter := confgenerator.ConvertGCMOtelExporterToOtlpExporter
if r.MetricsMode != "googlecloudmonitoring" {
converter = confgenerator.ConvertPrometheusExporterToOtlpExporter
}
return []otel.ReceiverPipeline{converter(otel.ReceiverPipeline{
ExporterTypes: map[string]otel.ExporterType{
"metrics": receiverPipelineType,
"traces": otel.OTel,
Expand All @@ -163,7 +167,7 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e
"traces": otel.SetIfMissing,
"logs": otel.SetIfMissing,
},
}}, nil
}, ctx)}, nil
}

func init() {
Expand Down
32 changes: 17 additions & 15 deletions confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,24 @@ func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context,
if !expOtlpExporter {
return pipeline
}
_, err := pipeline.ExporterTypes["metrics"]
if !err {
return pipeline
}
pipeline.ExporterTypes["metrics"] = otel.OTLP
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))
if isSystem {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
}
if _, ok := pipeline.ExporterTypes["metrics"]; ok {
pipeline.ExporterTypes["metrics"] = otel.OTLP
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))
if isSystem {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
}

// The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits.
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch())
if isPrometheus {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
// The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits.
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch())
if isPrometheus {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
}
}
if _, ok := pipeline.ExporterTypes["traces"]; ok {
pipeline.ExporterTypes["traces"] = otel.OTLP
pipeline.Processors["traces"] = append(pipeline.Processors["traces"], otel.GCPProjectID(resource.ProjectName()))
}
return pipeline
}
Expand Down
4 changes: 2 additions & 2 deletions integration_test/ops_agent_test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5223,7 +5223,7 @@ traces:

func TestOTLPTraces(t *testing.T) {
t.Parallel()
gce.RunForEachImage(t, func(t *testing.T, imageSpec string) {
RunForEachImageAndFeatureFlag(t, []string{OtlpHttpExporterFeatureFlag}, func(t *testing.T, imageSpec string, feature string) {
t.Parallel()
ctx, logger, vm := setupMainLogAndVM(t, imageSpec)
otlpConfig := `
Expand All @@ -5241,7 +5241,7 @@ metrics:
service:
pipelines:
`
if err := agents.SetupOpsAgent(ctx, logger, vm, otlpConfig); err != nil {
if err := SetupOpsAgentWithFeatureFlag(ctx, logger, vm, otlpConfig, feature); err != nil {
t.Fatal(err)
}

Expand Down
Loading