Skip to content

Commit

Permalink
Update metrics name
Browse files Browse the repository at this point in the history
Update metrics name
  • Loading branch information
yanweili committed Nov 19, 2024
1 parent dae9066 commit 12bc4af
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 39 additions & 0 deletions instana/otelcollector/otelcol-config-extras.yml
Original file line number Diff line number Diff line change
@@ -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]
46 changes: 0 additions & 46 deletions src/checkoutservice/runtimeMetrics.go

This file was deleted.

61 changes: 61 additions & 0 deletions src/checkoutservice/runtime_metrics.go
Original file line number Diff line number Diff line change
@@ -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)
}
37 changes: 8 additions & 29 deletions src/otelcollector/otelcol-config-extras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <your-endpoint-url>
#
# service:
# pipelines:
# traces:
# exporters: [spanmetrics, otlphttp/example]

Check failure on line 18 in src/otelcollector/otelcol-config-extras.yml

View workflow job for this annotation

GitHub Actions / yamllint

18:52 [new-line-at-end-of-file] no new line character at the end of file
2 changes: 1 addition & 1 deletion src/paymentservice/charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
File renamed without changes.

0 comments on commit 12bc4af

Please sign in to comment.