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
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ type Config struct {
ClientKeyPath string
// CACertPath specifies path to root CA cert, used to verify OTel collector cert.
CACertPath string
// ServiceInstanceID is the unique identifier for this instance of the service showing in OTel metrics.
ServiceInstanceID string
}
}

Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestParse(t *testing.T) {
ClientCertPath string
ClientKeyPath string
CACertPath string
ServiceInstanceID string
}{
Enabled: true,
OTELCollectorEndpoint: "http://localhost:4317",
Expand Down
13 changes: 11 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/theparanoids/crypki/certreload"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
"google.golang.org/grpc"
Expand Down Expand Up @@ -135,10 +136,18 @@ func Main() {
go logRotate(file)

if cfg.OTel.Enabled {
otelAttributes := []attribute.KeyValue{semconv.ServiceNameKey.String("crypki")}

if cfg.OTel.ServiceInstanceID == "" {
cfg.OTel.ServiceInstanceID = os.Getenv("SERVICE_INSTANCE_ID")
}
if cfg.OTel.ServiceInstanceID != "" {
otelAttributes = append(otelAttributes, semconv.ServiceInstanceIDKey.String(cfg.OTel.ServiceInstanceID))
}

otelResource, err := resource.Merge(
resource.Default(),
resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceNameKey.String("crypki"),
semconv.ServiceInstanceIDKey.String(os.Getenv("SERVICE_INSTANCE_ID"))),
resource.NewWithAttributes(semconv.SchemaURL, otelAttributes...),
)
if err != nil {
log.Fatalf("Error merging resources: %v", err)
Expand Down
Loading