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 3c7604e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
61 changes: 61 additions & 0 deletions exporter/collector/integrationtest/integration_selfobs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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()),
),
)
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 3c7604e

Please sign in to comment.