-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export self-observability metrics during the integration test
- Loading branch information
Showing
5 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
exporter/collector/integrationtest/integration_selfobs_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters