Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
!.env.example
storage
tmp
tests/testdata/otel-tls/
112 changes: 100 additions & 12 deletions config/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func init() {
// - "b3multi": B3 Multi Header
"propagators": config.Env("OTEL_PROPAGATORS", "tracecontext"),

// Shutdown Timeout
//
// Max time to wait for flushing buffered telemetry when the application stops.
// Format: Duration string (e.g., "15s", "30s").
"shutdown_timeout": config.Env("OTEL_SHUTDOWN_TIMEOUT", "15s"),

// Traces Configuration
//
// Configures the distributed tracing signal. Traces record the path of
Expand Down Expand Up @@ -69,6 +75,23 @@ func init() {
// e.g., 0.1 records ~10% of traces.
"ratio": config.Env("OTEL_TRACES_SAMPLER_RATIO", 1.0),
},

// Processor Configuration
//
// Controls how finished spans are handed to the exporter.
"processor": map[string]any{
// Type: "batch" buffers spans for performance (recommended);
// "simple" exports each span synchronously (debugging).
"type": config.Env("OTEL_TRACE_PROCESSOR_TYPE", "batch"),

// Interval: How often buffered spans are pushed.
// Format: Duration string (e.g., "5s", "1m", "500ms").
"interval": config.Env("OTEL_TRACE_EXPORT_INTERVAL", "5s"),

// Timeout: Max time allowed for export before cancelling.
// Format: Duration string (e.g., "30s", "10s").
"timeout": config.Env("OTEL_TRACE_EXPORT_TIMEOUT", "30s"),
},
},

// Metrics Configuration
Expand Down Expand Up @@ -110,14 +133,18 @@ func init() {

// Processor Configuration
//
// Configures the BatchLogProcessor, which batches logs before export.
// Controls how log records are handed to the exporter.
"processor": map[string]any{
// Interval: How often logs are flushed.
// Format: Duration string (e.g., "1s", "500ms").
// Type: "batch" buffers records for performance (recommended);
// "simple" exports each record synchronously (debugging).
"type": config.Env("OTEL_LOG_PROCESSOR_TYPE", "batch"),

// Interval: How often buffered records are pushed.
// Format: Duration string (e.g., "1s", "1m", "500ms").
"interval": config.Env("OTEL_LOG_EXPORT_INTERVAL", "10s"),

// Timeout: Max time allowed for export before cancelling.
// Format: Duration string (e.g., "30s").
// Format: Duration string (e.g., "30s", "10s").
"timeout": config.Env("OTEL_LOG_EXPORT_TIMEOUT", "10s"),
},
},
Expand Down Expand Up @@ -183,9 +210,9 @@ func init() {
// Reference: https://opentelemetry.io/docs/specs/otel/protocol/
"otlptrace": map[string]any{
"driver": "otlp",
"endpoint": config.Env("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "http://localhost:4318"),
"endpoint": config.Env("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "localhost:4318"),

// Protocol: "http/protobuf", "http/json" or "grpc".
// Protocol: "http/protobuf" or "grpc".
"protocol": config.Env("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "http/protobuf"),

// Set to false to require TLS/SSL.
Expand All @@ -194,14 +221,34 @@ func init() {
// Timeout: Max time to wait for the backend to acknowledge.
// Format: Duration string (e.g., "10s", "500ms").
"timeout": config.Env("OTEL_EXPORTER_OTLP_TRACES_TIMEOUT", "10s"),

// Compression: "gzip" or "" (none).
"compression": config.Env("OTEL_EXPORTER_OTLP_TRACES_COMPRESSION", ""),

// TLS certificate file paths. Leave empty to use system roots.
// Conflicts with "insecure".
"tls": map[string]any{
"ca": config.Env("OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE", ""),
"cert": config.Env("OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE", ""),
"key": config.Env("OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY", ""),
},

// Retry with exponential backoff on export failure.
// Zero durations use the SDK defaults shown below.
"retry": map[string]any{
"enabled": true,
"initial_interval": "5s",
"max_interval": "30s",
"max_elapsed_time": "1m",
},
},

// OTLP Metric Exporter
"otlpmetric": map[string]any{
"driver": "otlp",
"endpoint": config.Env("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "http://localhost:4318"),
"endpoint": config.Env("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "localhost:4318"),

// Protocol: "http/protobuf", "http/json" or "grpc".
// Protocol: "http/protobuf" or "grpc".
"protocol": config.Env("OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", "http/protobuf"),

// Set to false to require TLS/SSL.
Expand All @@ -211,18 +258,39 @@ func init() {
// Format: Duration string (e.g., "10s", "500ms").
"timeout": config.Env("OTEL_EXPORTER_OTLP_METRICS_TIMEOUT", "10s"),

// Metric Temporality: "cumulative" or "delta".
// Metric Temporality: "cumulative", "delta" or "lowmemory".
// - "cumulative": Standard for Prometheus (counts never reset).
// - "delta": Standard for Datadog/StatsD (counts per interval).
// - "delta": Standard for Datadog/StatsD. UpDownCounters stay cumulative per the OTLP spec.
// - "lowmemory": Delta for synchronous Counter/Histogram only.
"metric_temporality": config.Env("OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY", "cumulative"),

// Compression: "gzip" or "" (none).
"compression": config.Env("OTEL_EXPORTER_OTLP_METRICS_COMPRESSION", ""),

// TLS certificate file paths. Leave empty to use system roots.
// Conflicts with "insecure".
"tls": map[string]any{
"ca": config.Env("OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE", ""),
"cert": config.Env("OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE", ""),
"key": config.Env("OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY", ""),
},

// Retry with exponential backoff on export failure.
// Zero durations use the SDK defaults shown below.
"retry": map[string]any{
"enabled": true,
"initial_interval": "5s",
"max_interval": "30s",
"max_elapsed_time": "1m",
},
},

// OTLP Log Exporter
"otlplog": map[string]any{
"driver": "otlp",
"endpoint": config.Env("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "http://localhost:4318"),
"endpoint": config.Env("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "localhost:4318"),

// Protocol: "http/protobuf", "http/json" or "grpc".
// Protocol: "http/protobuf" or "grpc".
"protocol": config.Env("OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", "http/protobuf"),

// Set to false to require TLS/SSL.
Expand All @@ -231,6 +299,26 @@ func init() {
// Timeout: Max time to wait for the backend to acknowledge.
// Format: Duration string (e.g., "10s", "500ms").
"timeout": config.Env("OTEL_EXPORTER_OTLP_LOGS_TIMEOUT", "10s"),

// Compression: "gzip" or "" (none).
"compression": config.Env("OTEL_EXPORTER_OTLP_LOGS_COMPRESSION", ""),

// TLS certificate file paths. Leave empty to use system roots.
// Conflicts with "insecure".
"tls": map[string]any{
"ca": config.Env("OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE", ""),
"cert": config.Env("OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE", ""),
"key": config.Env("OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY", ""),
},

// Retry with exponential backoff on export failure.
// Zero durations use the SDK defaults shown below.
"retry": map[string]any{
"enabled": true,
"initial_interval": "5s",
"max_interval": "30s",
"max_elapsed_time": "1m",
},
},

// Console Exporter (Debugging)
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ services:
- "4317:4317"
- "4318:4318"

otel-collector-tls:
image: otel/opentelemetry-collector-contrib:latest
restart: always
command: ["--config=/etc/otel-config-tls.yaml"]
volumes:
- ./otel-config-tls.yaml:/etc/otel-config-tls.yaml
- ./tests/testdata/otel-tls:/etc/otel-tls:ro
ports:
- "4319:4319"

Comment on lines +14 to +23
jaeger:
image: jaegertracing/all-in-one:latest
restart: always
Expand Down
72 changes: 36 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ require (
github.com/swaggo/swag v1.16.2
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/vektah/gqlparser/v2 v2.5.19
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/metric v1.43.0
google.golang.org/grpc v1.80.0
go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel/metric v1.44.0
google.golang.org/grpc v1.81.1
)

require (
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/containerd/console v1.0.5 // indirect
github.com/dave/dst v0.27.3 // indirect
github.com/dave/dst v0.27.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dromara/carbon/v2 v2.6.11 // indirect
Expand Down Expand Up @@ -118,7 +118,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand All @@ -141,7 +141,7 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.21 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.22 // indirect
github.com/mattn/go-runewidth v0.0.24 // indirect
github.com/microsoft/go-mssqldb v1.9.1 // indirect
github.com/minio/crc64nvme v1.1.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
Expand Down Expand Up @@ -187,47 +187,47 @@ require (
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/unrolled/secure v1.17.0 // indirect
github.com/urfave/cli/v3 v3.8.0 // indirect
github.com/urfave/cli/v3 v3.9.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.71.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.43.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 // indirect
go.opentelemetry.io/otel/log v0.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.43.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.19.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.69.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.44.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.44.0 // indirect
go.opentelemetry.io/otel/log v0.20.0 // indirect
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.20.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/exp v0.0.0-20260312153236-7ab1446f8b90 // indirect
golang.org/x/mod v0.34.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/exp v0.0.0-20260603202125-055de637280b // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/term v0.42.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/term v0.43.0 // indirect
golang.org/x/text v0.37.0 // indirect
golang.org/x/time v0.12.0 // indirect
golang.org/x/tools v0.43.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
golang.org/x/tools v0.45.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.6.0 // indirect
Expand All @@ -237,4 +237,4 @@ require (
gorm.io/plugin/dbresolver v1.6.2 // indirect
)

replace github.com/goravel/framework => github.com/goravel/framework v1.17.2-0.20260408110243-4838a69e4bdd
replace github.com/goravel/framework => github.com/goravel/framework v1.17.2-0.20260610071514-89408709dd39
Loading
Loading