diff --git a/.env b/.env index adc21721c8..ccd277c06e 100644 --- a/.env +++ b/.env @@ -28,7 +28,7 @@ OTEL_COLLECTOR_HOST=otelcol OTEL_COLLECTOR_PORT_GRPC=4317 OTEL_COLLECTOR_PORT_HTTP=4318 OTEL_COLLECTOR_CONFIG=./src/otelcollector/otelcol-config.yml -OTEL_COLLECTOR_CONFIG_EXTRAS=./src/otelcollector/otelcol-config-extras.yml +OTEL_COLLECTOR_CONFIG_EXTRAS=./instana/otelcollector/otelcol-config-extras.yml OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTEL_COLLECTOR_HOST}:${OTEL_COLLECTOR_PORT_GRPC} PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:8080/otlp-http/v1/traces diff --git a/instana/otelcollector/otelcol-config-extras.yml b/instana/otelcollector/otelcol-config-extras.yml new file mode 100644 index 0000000000..1b6ab1c257 --- /dev/null +++ b/instana/otelcollector/otelcol-config-extras.yml @@ -0,0 +1,39 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# extra settings to be merged into OpenTelemetry Collector configuration +# do not delete this file + +## Example configuration for sending data to your own OTLP HTTP backend +## Note: the spanmetrics exporter must be included in the exporters array +## if overriding the traces pipeline. +## +processors: + resource: + attributes: + - key: service.instance.id + value: otel-demo + action: upsert + +# Replace the INSTANA_ENDPOINT, more information please refer to: +# https://www.ibm.com/docs/en/instana-observability/current?topic=opentelemetry-sending-data-instana +exporters: + otlp/instana: + endpoint: INSTANA_ENDPOINT + tls: + insecure: true + +service: + pipelines: + traces: + receivers: [otlp] + processors: [transform, batch, resource] + exporters: [otlp, debug, spanmetrics, otlp/instana] + metrics: + receivers: [otlp, spanmetrics] + processors: [batch, resource] + exporters: [otlphttp/prometheus, debug, otlp/instana] + logs: + receivers: [otlp] + processors: [batch, resource] + exporters: [opensearch, debug] diff --git a/src/checkoutservice/runtimeMetrics.go b/src/checkoutservice/runtimeMetrics.go deleted file mode 100644 index 354b0b4185..0000000000 --- a/src/checkoutservice/runtimeMetrics.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -package main - -import ( - "context" - "runtime" - - "go.opentelemetry.io/otel/metric" -) - -func recordRuntimeMetrics(meter metric.Meter) error { - // Create metric instruments - gcPause, err := meter.Float64ObservableGauge("go_gc_pause") - if err != nil { - return err - } - - allocatedMemory, err := meter.Float64ObservableGauge("go_allocated_memory") - if err != nil { - return err - } - - memoryObtainedFromSystem, err := meter.Float64ObservableGauge("go_memory_obtained_from_system") - if err != nil { - return err - } - - // Record the runtime stats periodically - if _, err := meter.RegisterCallback( - func(ctx context.Context, o metric.Observer) error { - var memStats runtime.MemStats - runtime.ReadMemStats(&memStats) - - o.ObserveFloat64(gcPause, float64(memStats.PauseTotalNs)/1e6) // GC Pause in ms - o.ObserveFloat64(allocatedMemory, float64(memStats.Alloc)) // Allocated Memory in B - o.ObserveFloat64(memoryObtainedFromSystem, float64(memStats.Sys)) // Memory Obtained From System in B - return nil - }, - gcPause, allocatedMemory, memoryObtainedFromSystem, - ); err != nil { - return err - } - - return nil -} diff --git a/src/checkoutservice/runtime_metrics.go b/src/checkoutservice/runtime_metrics.go new file mode 100644 index 0000000000..b69bf38a02 --- /dev/null +++ b/src/checkoutservice/runtime_metrics.go @@ -0,0 +1,61 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 +package main + +import ( + "context" + "math" + "runtime" + + "go.opentelemetry.io/otel/metric" +) + +func recordRuntimeMetrics(meter metric.Meter) error { + // Create metric instruments + + var ( + err error + + memSys metric.Int64ObservableUpDownCounter + pauseTotalMs metric.Int64ObservableCounter + ) + + if pauseTotalMs, err = meter.Int64ObservableCounter( + "process.runtime.go.gc.pause_total_ms", + metric.WithDescription("Cumulative nanoseconds in GC stop-the-world pauses since the program started"), + ); err != nil { + return err + } + + if memSys, err = meter.Int64ObservableUpDownCounter( + "process.runtime.go.mem.sys", + metric.WithUnit("By"), + metric.WithDescription("Bytes of memory obtained from the OS"), + ); err != nil { + return err + } + + // Record the runtime stats periodically + if _, err := meter.RegisterCallback( + func(ctx context.Context, o metric.Observer) error { + var memStats runtime.MemStats + runtime.ReadMemStats(&memStats) + + o.ObserveInt64(pauseTotalMs, clampUint64(memStats.PauseTotalNs)/1e6) // GC Pause in ms + o.ObserveInt64(memSys, clampUint64(memStats.Sys)) + return nil + }, + pauseTotalMs, memSys, + ); err != nil { + return err + } + + return nil +} + +func clampUint64(v uint64) int64 { + if v > math.MaxInt64 { + return math.MaxInt64 + } + return int64(v) +} diff --git a/src/otelcollector/otelcol-config-extras.yml b/src/otelcollector/otelcol-config-extras.yml index d9d40cd7c4..2f955cac7f 100644 --- a/src/otelcollector/otelcol-config-extras.yml +++ b/src/otelcollector/otelcol-config-extras.yml @@ -8,32 +8,11 @@ ## Note: the spanmetrics exporter must be included in the exporters array ## if overriding the traces pipeline. ## -processors: - resource: - attributes: - - key: service.instance.id - value: otel-demo - action: upsert - -exporters: - otlp/instana: - endpoint: - headers: - x-instana-key: - tls: - insecure: true - -service: - pipelines: - traces: - receivers: [otlp] - processors: [transform, batch, resource] - exporters: [otlp, debug, spanmetrics, otlp/instana] - metrics: - receivers: [otlp, spanmetrics] - processors: [batch, resource] - exporters: [otlphttp/prometheus, debug, otlp/instana] - logs: - receivers: [otlp] - processors: [batch, resource] - exporters: [opensearch, debug] +# exporters: +# otlphttp/example: +# endpoint: +# +# service: +# pipelines: +# traces: +# exporters: [spanmetrics, otlphttp/example] \ No newline at end of file diff --git a/src/paymentservice/charge.js b/src/paymentservice/charge.js index e34e31fa8a..9f63620fd8 100644 --- a/src/paymentservice/charge.js +++ b/src/paymentservice/charge.js @@ -9,7 +9,7 @@ const { FlagdProvider} = require('@openfeature/flagd-provider'); const flagProvider = new FlagdProvider(); const logger = require('./logger'); -const runtimeMetrics = require('./runtimeMetrics'); +const runtimeMetrics = require('./runtime-metrics'); const tracer = trace.getTracer('paymentservice'); const meter = metrics.getMeter('paymentservice'); const transactionsCounter = meter.createCounter('app.payment.transactions') diff --git a/src/paymentservice/runtimeMetrics.js b/src/paymentservice/runtime-metrics.js similarity index 100% rename from src/paymentservice/runtimeMetrics.js rename to src/paymentservice/runtime-metrics.js