Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opentelemetry instrumentation for QueryNode graphql-server #5104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions opentelemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api'
import { NodeSDK } from '@opentelemetry/sdk-node'
import 'dotenv/config'
import { DefaultInstrumentation, DistributorNodeInstrumentation, StorageNodeInstrumentation } from './instrumentations'
import {
DefaultInstrumentation,
DistributorNodeInstrumentation,
GraphqlServerInstrumentation,
StorageNodeInstrumentation,
} from './instrumentations'

// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO)
Expand All @@ -18,7 +23,7 @@ function addInstrumentation() {
instrumentation = StorageNodeInstrumentation
diag.info(`Loaded Application Instrumentation: "Storage Node"`)
} else if (applicationName === 'query-node') {
instrumentation = DefaultInstrumentation
instrumentation = GraphqlServerInstrumentation
diag.info(`Loaded Application Instrumentation: "Query Node"`)
} else {
instrumentation = DefaultInstrumentation
Expand Down
28 changes: 28 additions & 0 deletions opentelemetry/instrumentations/graphql-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node'

/** Opentelemetry Instrumentation for Query Node's graphql-server */

export const GraphqlServerInstrumentation = new NodeSDK({
spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter(), {
maxQueueSize: parseInt(process.env.OTEL_MAX_QUEUE_SIZE || '8192'),
maxExportBatchSize: parseInt(process.env.OTEL_MAX_EXPORT_BATCH_SIZE || '1024'),
}),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
}),
instrumentations: [
// Disable DNS instrumentation, because the instrumentation does not correctly patches `dns.lookup` function
// if the function is converted to a promise-based method using `utils.promisify(dns.lookup)`
// See: https://github.com/Joystream/joystream/pull/4779#discussion_r1262515887
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-dns': { enabled: false },
'@opentelemetry/instrumentation-pg': { enhancedDatabaseReporting: true },
'@opentelemetry/instrumentation-graphql': { allowValues: true },
}),
],
})
1 change: 1 addition & 0 deletions opentelemetry/instrumentations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './default'
export * from './distributor-node'
export * from './graphql-server'
export * from './storage-node'