Skip to content
Merged
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
12 changes: 10 additions & 2 deletions cmd/tesseract/gcp/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"context"
"errors"
"os"

"go.opentelemetry.io/contrib/detectors/gcp"
"go.opentelemetry.io/otel"
Expand All @@ -27,6 +28,7 @@ import (

mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
"github.com/google/uuid"
"k8s.io/klog/v2"
)

Expand All @@ -49,14 +51,20 @@ func initOTel(ctx context.Context, traceFraction float64, origin string, project
}
}

instanceID, err := os.Hostname()
if err != nil {
klog.Errorf("os.Hostname() failed, setting OTel service instance ID to UUID. Error: %v", err)
instanceID = uuid.NewString()
}
resources, err := resource.New(ctx,
resource.WithTelemetrySDK(),
resource.WithFromEnv(), // unpacks OTEL_RESOURCE_ATTRIBUTES
// Add your own custom attributes to identify your application
resource.WithAttributes(
semconv.ServiceNameKey.String(origin),
semconv.ServiceNamespaceKey.String("tesseract"),
semconv.ServiceNameKey.String(origin),
semconv.ServiceInstanceIDKey.String(instanceID),
),
resource.WithFromEnv(), // unpacks OTEL_RESOURCE_ATTRIBUTES
resource.WithDetectors(gcp.NewDetector()),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/gdamore/tcell/v2 v2.13.8
github.com/go-sql-driver/mysql v1.9.3
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/johannesboyne/gofakes3 v0.0.0-20250916175020-ebf3e50324d3
github.com/kylelemons/godebug v1.1.0
github.com/rivo/tview v0.42.0
Expand Down Expand Up @@ -99,7 +100,6 @@ require (
github.com/google/flatbuffers v25.2.10+incompatible // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.11 // indirect
github.com/googleapis/gax-go/v2 v2.16.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
Expand Down
Loading