diff --git a/pkg/constant/env.go b/pkg/constant/env.go index 2ce4cb0..f7a2d22 100644 --- a/pkg/constant/env.go +++ b/pkg/constant/env.go @@ -1,11 +1,11 @@ package constant const ( - EnvKeyOTLPEnabled = "OTLP_ENABLED" - EnvKeyOTLPCollectorUrl = "OTLP_COLLECTOR_URL" - EnvKeyOTLPInsecure = "OTLP_INSECURE" - EnvKeyOTLPProtocol = "OTLP_PROTOCOL" - EnvKeyOTLPServiceName = "OTLP_SERVICE_NAME" - EnvKeyOTLPServiceVersion = "OTLP_SERVICE_VERSION" - EnvKeyOTLPTraceSampleRate = "OTLP_TRACE_SAMPLE_RATE" + EnvKeyOtelEnabled = "OTEL_ENABLED" + EnvKeyOtelCollectorUrl = "OTEL_COLLECTOR_URL" + EnvKeyOtelInsecure = "OTEL_INSECURE" + EnvKeyOtelProtocol = "OTEL_PROTOCOL" + EnvKeyOtelServiceName = "OTEL_SERVICE_NAME" + EnvKeyOtelServiceVersion = "OTEL_SERVICE_VERSION" + EnvKeyOtelTraceSampleRate = "OTEL_TRACE_SAMPLE_RATE" ) diff --git a/pkg/constant/otlp.go b/pkg/constant/otlp.go index 1a8bfb5..7ed598a 100644 --- a/pkg/constant/otlp.go +++ b/pkg/constant/otlp.go @@ -1,9 +1,9 @@ package constant const ( - OTLPDefaultServiceName = "default-service-name" - OTLPDefaultServiceVersion = "0.1.0" - OTLPProtocolGRPC = "grpc" - OTLPProtocolHTTP = "http" - OTLPDefaultSampleRate = 0.5 + OtelDefaultServiceName = "default-service-name" + OtelDefaultServiceVersion = "0.1.0" + OtelProtocolGRPC = "grpc" + OtelProtocolHTTP = "http" + OtelDefaultSampleRate = 0.5 ) diff --git a/pkg/metric/init.go b/pkg/metric/init.go index 9e37317..7c33086 100644 --- a/pkg/metric/init.go +++ b/pkg/metric/init.go @@ -6,7 +6,7 @@ import ( ) func init() { - if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) { + if env.BoolFromEnv(constant.EnvKeyOtelEnabled) { InitProvider() } } diff --git a/pkg/metric/meter.go b/pkg/metric/meter.go index 5335aae..3deb9a5 100644 --- a/pkg/metric/meter.go +++ b/pkg/metric/meter.go @@ -9,5 +9,5 @@ import ( ) func Meter() metric.Meter { - return otel.GetMeterProvider().Meter(env.StringFromEnv(constant.EnvKeyOTLPServiceName, constant.OTLPDefaultServiceName)) + return otel.GetMeterProvider().Meter(env.StringFromEnv(constant.EnvKeyOtelServiceName, constant.OtelDefaultServiceName)) } diff --git a/pkg/metric/provider.go b/pkg/metric/provider.go index fab7a7a..f7593dd 100644 --- a/pkg/metric/provider.go +++ b/pkg/metric/provider.go @@ -54,12 +54,12 @@ func newOTLPExporter() (metric.Exporter, error) { ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, time.Second) defer cancel() - providerServerUrl := env.StringFromEnv(constant.EnvKeyOTLPCollectorUrl, "") - isInsecure := env.BoolFromEnv(constant.EnvKeyOTLPInsecure) - protocol := env.StringFromEnv(constant.EnvKeyOTLPProtocol, constant.OTLPProtocolGRPC) + providerServerUrl := env.StringFromEnv(constant.EnvKeyOtelCollectorUrl, "") + isInsecure := env.BoolFromEnv(constant.EnvKeyOtelInsecure) + protocol := env.StringFromEnv(constant.EnvKeyOtelProtocol, constant.OtelProtocolGRPC) // gRPC - if protocol == constant.OTLPProtocolGRPC { + if protocol == constant.OtelProtocolGRPC { return newGRPCExporter(ctx, providerServerUrl, isInsecure) } @@ -72,8 +72,8 @@ func newResources() *resource.Resource { // ref: https://opentelemetry.io/docs/instrumentation/go/resources/ return resource.NewWithAttributes( semconv.SchemaURL, - semconv.ServiceName(env.StringFromEnv(constant.EnvKeyOTLPServiceName, constant.OTLPDefaultServiceName)), - semconv.ServiceVersion(env.StringFromEnv(constant.EnvKeyOTLPServiceVersion, constant.OTLPDefaultServiceVersion)), + semconv.ServiceName(env.StringFromEnv(constant.EnvKeyOtelServiceName, constant.OtelDefaultServiceName)), + semconv.ServiceVersion(env.StringFromEnv(constant.EnvKeyOtelServiceVersion, constant.OtelDefaultServiceVersion)), ) } diff --git a/pkg/tracer/init.go b/pkg/tracer/init.go index 5bddfd7..32104ff 100644 --- a/pkg/tracer/init.go +++ b/pkg/tracer/init.go @@ -6,7 +6,7 @@ import ( ) func init() { - if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) { + if env.BoolFromEnv(constant.EnvKeyOtelEnabled) { InitProvider() } } diff --git a/pkg/tracer/provider.go b/pkg/tracer/provider.go index 5ef4495..c9e18a6 100644 --- a/pkg/tracer/provider.go +++ b/pkg/tracer/provider.go @@ -60,12 +60,12 @@ func newOTLPExporter() (*otlptrace.Exporter, error) { ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, time.Second) defer cancel() - providerServerUrl := env.StringFromEnv(constant.EnvKeyOTLPCollectorUrl, "") - isInsecure := env.BoolFromEnv(constant.EnvKeyOTLPInsecure) - protocol := env.StringFromEnv(constant.EnvKeyOTLPProtocol, constant.OTLPProtocolGRPC) + providerServerUrl := env.StringFromEnv(constant.EnvKeyOtelCollectorUrl, "") + isInsecure := env.BoolFromEnv(constant.EnvKeyOtelInsecure) + protocol := env.StringFromEnv(constant.EnvKeyOtelProtocol, constant.OtelProtocolGRPC) // gRPC - if protocol == constant.OTLPProtocolGRPC { + if protocol == constant.OtelProtocolGRPC { return newGRPCExporter(ctx, providerServerUrl, isInsecure) } @@ -78,8 +78,8 @@ func newResources() *resource.Resource { // ref: https://opentelemetry.io/docs/instrumentation/go/resources/ return resource.NewWithAttributes( semconv.SchemaURL, - semconv.ServiceName(env.StringFromEnv(constant.EnvKeyOTLPServiceName, constant.OTLPDefaultServiceName)), - semconv.ServiceVersion(env.StringFromEnv(constant.EnvKeyOTLPServiceVersion, constant.OTLPDefaultServiceVersion)), + semconv.ServiceName(env.StringFromEnv(constant.EnvKeyOtelServiceName, constant.OtelDefaultServiceName)), + semconv.ServiceVersion(env.StringFromEnv(constant.EnvKeyOtelServiceVersion, constant.OtelDefaultServiceVersion)), ) } @@ -100,7 +100,7 @@ func InitProvider() { // Register the trace exporter with a TracerProvider, using a batch span processor to aggregate spans before export. bsp := trace.NewBatchSpanProcessor(exporter) - sampleRate := env.FloatFromEnv(constant.EnvKeyOTLPTraceSampleRate, constant.OTLPDefaultSampleRate) + sampleRate := env.FloatFromEnv(constant.EnvKeyOtelTraceSampleRate, constant.OtelDefaultSampleRate) // init tracer provider provider = trace.NewTracerProvider( diff --git a/pkg/tracer/tracer.go b/pkg/tracer/tracer.go index 90fd852..d78b80f 100644 --- a/pkg/tracer/tracer.go +++ b/pkg/tracer/tracer.go @@ -9,5 +9,5 @@ import ( ) func Tracer() trace.Tracer { - return otel.Tracer(env.StringFromEnv(constant.EnvKeyOTLPServiceName, constant.OTLPDefaultServiceName)) + return otel.Tracer(env.StringFromEnv(constant.EnvKeyOtelServiceName, constant.OtelDefaultServiceName)) }