Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(infra): add container id to service name of attribute metrics #1685

Merged
merged 8 commits into from
May 10, 2024
4 changes: 4 additions & 0 deletions apps/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func main() {
if env == "production" {
// load container Id from args
containerId := os.Args[1]
if len(containerId) == 0 {
logProvider.Log(logger.ERROR, "Cannot find containerId Args")
}

if utils.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT_URL", "") != "" {
shutdown := observability.InitTracer(ctx)
defer shutdown()
Expand Down
6 changes: 4 additions & 2 deletions apps/iris/src/observability/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func newMetricResource(containerId string) (*resource.Resource, error) {
resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("iris-metric"),
semconv.ServiceVersion("0.1.0"),
semconv.ServiceInstanceID(getInstanceId()),
semconv.ContainerID(containerId),
semconv.ServiceInstanceID(concatString(getInstanceId(), containerId)),
))
}

func concatString(instanceId string, containerId string) string {
return instanceId + "-" + containerId
}
func newMeterProvider(res *resource.Resource, second time.Duration) (*sdkmetric.MeterProvider, error) {
// Use OLTP Exporter for Grafana Agent (Recommended)
entryPoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT_URL")
Expand Down
Loading
Loading