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.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: '6bd4cb15802af388',
  traceState: undefined,
  name: 'encode',
  id: 'da01b95998af1310',
  kind: 0,
  timestamp: 1730125689574000,
  duration: 1388.042,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: '6bd4cb15802af388',
  traceState: undefined,
  name: 'pack',
  id: '269378c8ef1b74a2',
  kind: 0,
  timestamp: 1730125689577000,
  duration: 11309.583,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: '6bd4cb15802af388',
  traceState: undefined,
  name: 'exchange',
  id: 'bf1490ed8d17bfba',
  kind: 0,
  timestamp: 1730125689589000,
  duration: 20820.458,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: '6bd4cb15802af388',
  traceState: undefined,
  name: 'unpack',
  id: '9b7ed752b79d9543',
  kind: 0,
  timestamp: 1730125689610000,
  duration: 1649.458,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: '6bd4cb15802af388',
  traceState: undefined,
  name: 'decode',
  id: '3aafa22c23adfb5d',
  kind: 0,
  timestamp: 1730125689612000,
  duration: 209.833,
  attributes: {},
  status: { code: 0 },
  events: [],
  links: []
}
txt
{
  resource: {
    attributes: {
      'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '1.27.0'
    }
  },
  instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
  traceId: 'a15d7e95d85b3bf2bc123f8acaf94d5d',
  parentId: undefined,
  traceState: undefined,
  name: 'request',
  id: '6bd4cb15802af388',
  kind: 0,
  timestamp: 1730125689573000,
  duration: 38858.25,
  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.