How to use Ruby's telemetry SDK to send gauge metric

The git repo does not show an example of how to do this and my attempts at using the method have been unsuccessful. Can someone please give a simple code example?

Here is my attempt:

require 'newrelic/telemetry_sdk'

NewRelic::TelemetrySdk.configure do |config|
  config.api_insert_key = ENV["NEW_RELIC_INSERT_KEY"]
  config.audit_logging_enabled = true

client =
  host: "",
  path: "/metric/v1",
  payload_type: "metrics"

data = {
  :name => "test.testy",
  :type => "gauge",
  :value => 2.8,
  :timestamp => ( * 1000).to_i,
  :attributes => {"": "app"}
} data

But i get a Bad Request error back.

The “equivalent” curl call does work however

curl -vvv -k -H "Content-Type: application/json" \
  -X POST \
  --data '[{"metrics":[{"name":"test.curl","type":"gauge","value":2.8,"timestamp":1623182684000,"attributes":{"":"app"}}]}]'

Figured it out. It would really help to add an example for this in the examples dir by the way.

the client needs to be configured with ALL the necessary headers:

client =
  host: "",
  path: "/metric/v1",
  payload_type: "metrics",
  headers: {
    "Content-Type": "application/json",

And the NewRelic::TelemetrySdk.configure block is not needed. Otherwise the code in the original post is fine.

Not sure why headers is an optional parameter (with an empty object as the default!) given that it’s absolutely necessary for the client to work…