-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split into otel stuff into seperate module
- Loading branch information
1 parent
8676ad8
commit 1ae80b2
Showing
6 changed files
with
75 additions
and
64 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
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,54 @@ | ||
package otel_metrics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||
"go.opentelemetry.io/otel/metric" | ||
sdkmetric "go.opentelemetry.io/otel/sdk/metric" | ||
"go.opentelemetry.io/otel/sdk/resource" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.24.0" | ||
) | ||
|
||
type OtelManager struct { | ||
MetricsProvider *sdkmetric.MeterProvider | ||
Meter metric.Meter | ||
Float64GaugesCache map[string]*Float64Gauge | ||
Int64GaugesCache map[string]*Int64Gauge | ||
} | ||
|
||
// newOtelResource returns a resource describing this application. | ||
func newOtelResource(otelServiceName string) (*resource.Resource, error) { | ||
r, err := resource.Merge( | ||
resource.Default(), | ||
resource.NewWithAttributes( | ||
semconv.SchemaURL, | ||
semconv.ServiceNameKey.String(otelServiceName), | ||
), | ||
) | ||
|
||
return r, err | ||
} | ||
|
||
func SetupOtelMetricsExporter() (*sdkmetric.MeterProvider, error) { | ||
metricExporter, err := otlpmetrichttp.New(context.Background(), | ||
otlpmetrichttp.WithCompression(otlpmetrichttp.GzipCompression), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create OpenTelemetry metrics exporter: %w", err) | ||
} | ||
|
||
resource, err := newOtelResource("flow-worker") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create OpenTelemetry resource: %w", err) | ||
} | ||
|
||
meterProvider := sdkmetric.NewMeterProvider( | ||
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(metricExporter, | ||
sdkmetric.WithInterval(3*time.Second))), | ||
sdkmetric.WithResource(resource), | ||
) | ||
return meterProvider, nil | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package shared | ||
package otel_metrics | ||
|
||
import ( | ||
"context" | ||
|