OpenTelemetry collector does not export Metric attributes to New Relic

1.6k views Asked by At

I am attempting to export Metrics to an OpenTelemetry collector container from my Node.js app, which then exports it to New Relic.

I am making a simple request counter:

const exporter = new OTLPMetricExporter();


const meter = new MeterProvider({
    exporter,
    interval: 10 * 1000,
    resource: new Resource({
        [SemanticResourceAttributes.SERVICE_NAME]: 'otlp-service',
    }),
}).getMeter('my-meter-name');

const requestCount = meter.createCounter('api.requests', {
    description: 'Count all incoming requests to API.',
});

...

onResponseFinished(res, () => {
        const statusCode = res.statusCode ? res.statusCode : 'N/A';
        const labels = { statusCode };
        requestCount.add(1, labels);
};

I want to use the status code attribute to be able to facet/group by different status codes in New Relic. For this, I need to export the status code attribute (label) alongside each request so I can use them in New Relic. However, these labels do not get exported in OTLP and are neither displayed in the logging exporter. I have read about the resource_to_telemetry_conversion: enabled: true setting on the OpenTelemetry GitHub page on export helpers and used in conjunction with Prometheus in this StackOverflow issue, however, adding this attribute to my OTLP exporter configuration causes it to shut down due to an invalid configuration file; it seems it was only meant to be used with Prometheus and not generally with OTLP.

This is my otel-config.yml:

extensions:
  health_check: {}
receivers:
  otlp:
    protocols:
      grpc:
processors:
  batch: # compresses data and reduces number of outgoing connections.
exporters:
  logging:
    logLevel: debug
  otlp:
    endpoint: https://otlp.nr-data.net:4317
    headers:
      api-key: $NEW_RELIC_API_KEY
service:
  extensions: [health_check]
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, otlp]
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, otlp]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, otlp]

I am using WSL2 and:

➜  ~ docker-compose --version
docker-compose version 1.29.2, build 5becea4c
➜  ~ node --version
v14.18.1

package.json excerpt:

...
        "@opentelemetry/api": "^1.0.4",
        "@opentelemetry/exporter-metrics-otlp-grpc": "^0.27.0",
        "@opentelemetry/resources": "^1.0.1",
        "@opentelemetry/sdk-metrics-base": "^0.27.0",
        "@opentelemetry/semantic-conventions": "^1.0.1",
...

My question is: What settings need to be changed to export Metric attributes via OTLP, and for them to appear in New Relic?

Thank you

1

There are 1 answers

0
martinx On

I found out this is caused by a version mismatch, as the opentelemetry-js library JS OTLP exporters are still using an outdated version of protobufs. The problem is being tracked under this issue.