Skip to content

Commit

Permalink
export self-observability metrics during the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 9, 2024
1 parent cc36437 commit dddd2db
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
2 changes: 1 addition & 1 deletion exporter/collector/integrationtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.48.2
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.2
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.109.0
go.opentelemetry.io/collector/exporter v0.109.0
Expand Down Expand Up @@ -50,7 +51,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
Expand Down
64 changes: 64 additions & 0 deletions exporter/collector/integrationtest/integration_selfobs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integrationtest
// +build integrationtest

package integrationtest

import (
"context"
"log"
"os"
"testing"

"github.com/google/uuid"
"go.opentelemetry.io/otel"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"

mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
)

func TestMain(m *testing.M) {
ctx := context.Background()
exporter, err := mexporter.New(mexporter.WithProjectID(os.Getenv("PROJECT_ID")))
if err != nil {
log.Fatalf("Failed to create self-obs exporter: %v", err)
}
version4Uuid, err := uuid.NewRandom()
if err != nil {
log.Fatalf("Failed to create uuid for resource: %v", err)
}
res, err := resource.New(
ctx,
resource.WithTelemetrySDK(),
resource.WithFromEnv(),
resource.WithAttributes(
semconv.ServiceNameKey.String("integrationtest"),
semconv.ServiceInstanceIDKey.String(version4Uuid.String()),
),
)
if err != nil {
log.Fatalf("Failed to create self-obs resource: %v", err)
}
mp := sdkmetric.NewMeterProvider(
sdkmetric.WithResource(res),
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exporter)),
)
defer mp.Shutdown(ctx)
otel.SetMeterProvider(mp)
m.Run()
}
4 changes: 2 additions & 2 deletions exporter/collector/integrationtest/logs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel"
"go.uber.org/zap"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
Expand All @@ -49,7 +49,7 @@ func createLogsExporter(
ctx,
cfg,
logger,
noop.NewMeterProvider(),
otel.GetMeterProvider(),
"latest",
duration,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel"
"go.uber.org/zap"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
Expand All @@ -48,7 +48,7 @@ func createMetricsExporter(
ctx,
cfg,
logger,
noop.NewMeterProvider(),
otel.GetMeterProvider(),
"latest",
collector.DefaultTimeout,
)
Expand Down
4 changes: 2 additions & 2 deletions exporter/collector/integrationtest/traces_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/integrationtest/testcases"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
)

Expand All @@ -43,7 +43,7 @@ func createTracesExporter(
ctx,
cfg,
logger,
noop.NewMeterProvider(),
otel.GetMeterProvider(),
"latest",
collector.DefaultTimeout,
)
Expand Down

0 comments on commit dddd2db

Please sign in to comment.