Skip to content

Commit

Permalink
refactor: change env key from OTLP... to OTEL...
Browse files Browse the repository at this point in the history
  • Loading branch information
anhvietnguyennva committed Aug 21, 2023
1 parent b09136c commit 43e87b6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions pkg/constant/env.go
Original file line number Diff line number Diff line change
@@ -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"
)
10 changes: 5 additions & 5 deletions pkg/constant/otlp.go
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion pkg/metric/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func init() {
if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) {
if env.BoolFromEnv(constant.EnvKeyOtelEnabled) {
InitProvider()
}
}
2 changes: 1 addition & 1 deletion pkg/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
12 changes: 6 additions & 6 deletions pkg/metric/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)),
)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/tracer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func init() {
if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) {
if env.BoolFromEnv(constant.EnvKeyOtelEnabled) {
InitProvider()
}
}
14 changes: 7 additions & 7 deletions pkg/tracer/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)),
)
}

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 43e87b6

Please sign in to comment.