-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add oTel grpc instrumentation (#515)
- Loading branch information
Showing
15 changed files
with
222 additions
and
24 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
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,40 @@ | ||
// Copyright 2024 Yahoo Inc. | ||
// Licensed under the terms of the Apache License 2.0. Please see LICENSE file in project root for terms. | ||
|
||
package otellib | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"log" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||
sdkmetric "go.opentelemetry.io/otel/sdk/metric" | ||
"go.opentelemetry.io/otel/sdk/resource" | ||
) | ||
|
||
// InitOTelSDK initializes the OTel meter provider | ||
func InitOTelSDK(ctx context.Context, collectorEndpoint string, tlsConfig *tls.Config, res *resource.Resource) (shutdown func(context.Context) error) { | ||
// Set up an OTel exporter for metrics. | ||
var opts []otlpmetrichttp.Option | ||
opts = append(opts, otlpmetrichttp.WithEndpoint(collectorEndpoint)) | ||
opts = append(opts, otlpmetrichttp.WithTLSClientConfig(tlsConfig)) | ||
|
||
metricExporter, err := otlpmetrichttp.New(ctx, opts...) | ||
if err != nil { | ||
log.Fatalf("failed to create metric exporter: %v", err) | ||
} | ||
|
||
// Set up a metric provider. | ||
meterProvider := sdkmetric.NewMeterProvider( | ||
sdkmetric.WithReader( | ||
sdkmetric.NewPeriodicReader(metricExporter), | ||
), | ||
sdkmetric.WithResource(res), | ||
) | ||
|
||
otel.SetMeterProvider(meterProvider) | ||
|
||
return meterProvider.Shutdown | ||
} |
Oops, something went wrong.