2024-08-27 05:32:24 +00:00
|
|
|
package plug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-08-27 06:26:39 +00:00
|
|
|
|
2024-10-16 10:20:21 +00:00
|
|
|
"git.anthrove.art/Anthrove/plug-sdk/v4/pkg/telemetry"
|
2024-08-27 05:32:24 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetupOpenTelemtry(ctx context.Context, serviceName string) error {
|
|
|
|
ctx, span := tracer.Start(ctx, "SetupOpenTelemtry")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
err := telemetry.SetupMeterProvider(serviceName)
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, err.Error())
|
|
|
|
log.WithContext(ctx).WithError(err).Error("Failed to setup meter provider")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = telemetry.SetupTraceProvider(ctx, serviceName)
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, err.Error())
|
|
|
|
log.WithContext(ctx).WithError(err).Error("Failed to setup trace provider")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|