Skip to content
Graffle is a work in progress. Learn more.

Opentelemetry

ts

import { 
ConsoleSpanExporter
,
SimpleSpanProcessor
} from '@opentelemetry/sdk-trace-base'
import {
NodeTracerProvider
} from '@opentelemetry/sdk-trace-node'
import {
Opentelemetry
} from 'graffle/extensions/opentelemetry'
import {
Graffle
} from './graffle/__.js'
// Setup Opentelemetry // 1. Initialize the OpenTelemetry provider // 2. Register the provider to make the OpenTelemetry API use it const
exporter
= new
ConsoleSpanExporter
()
const
processor
= new
SimpleSpanProcessor
(
exporter
)
const
provider
= new
NodeTracerProvider
()
provider
.
addSpanProcessor
(
processor
)
provider
.
register
()
const
graffle
=
Graffle
.
create
().
use
(
Opentelemetry
())
const
data
= await
graffle
.
gql
`query { pokemons { name } }`.
send
()
console.log(
data
)

Outputs

txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: 'd6c3800b8979fcd8',
  traceState: undefined,
  name: 'encode',
  id: '4efad046792865d3',
  kind: 0,
  timestamp: 1736741813348000,
  duration: 875.167,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: 'd6c3800b8979fcd8',
  traceState: undefined,
  name: 'pack',
  id: '29d86e3c651e066b',
  kind: 0,
  timestamp: 1736741813349000,
  duration: 7728.833,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: 'd6c3800b8979fcd8',
  traceState: undefined,
  name: 'exchange',
  id: '5ded2022385d9c01',
  kind: 0,
  timestamp: 1736741813358000,
  duration: 20876.084,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: 'd6c3800b8979fcd8',
  traceState: undefined,
  name: 'unpack',
  id: '609e080ad2ff4514',
  kind: 0,
  timestamp: 1736741813379000,
  duration: 744.917,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: 'd6c3800b8979fcd8',
  traceState: undefined,
  name: 'decode',
  id: '60c901a55f2139da',
  kind: 0,
  timestamp: 1736741813379000,
  duration: 376.5,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.11.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.30.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: '305fecdf1d521d48b39e0f3dde5e32e1',
  parentId: undefined,
  traceState: undefined,
  name: 'request',
  id: 'd6c3800b8979fcd8',
  kind: 0,
  timestamp: 1736741813347000,
  duration: 32641.166,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  pokemons: [
    { name: 'Pikachu' },
    { name: 'Charizard' },
    { name: 'Squirtle' },
    { name: 'Bulbasaur' },
    { name: 'Caterpie' },
    { name: 'Weedle' }
  ]
}

Released under the MIT License.