OpenTelemetry tracing
Export SignatureKit spans for PDF parsing, signing and provider calls to an OTLP collector or the console.
Every public SignatureKit operation runs inside an Effect span. PDF parsing, Markdown extraction, certificate loading, signing, verification and remote-provider calls each produce one. The packages only use Effect's built-in tracer and depend on neither @opentelemetry/api nor an SDK. If your app doesn't install an exporter, Effect's native tracer discards each span when it ends.
To export them, provide the official @effect/opentelemetry layer at the app boundary.
bun add @effect/opentelemetry @opentelemetry/api @opentelemetry/resources \
@opentelemetry/sdk-trace-base @opentelemetry/sdk-trace-node \
@opentelemetry/semantic-conventions @opentelemetry/exporter-trace-otlp-httptitle="tracing.ts"
import { readFile } from "node:fs/promises"
import * as NodeSdk from "@effect/opentelemetry/NodeSdk"
import * as NodeServices from "@effect/platform-node/NodeServices"
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
import {
BatchSpanProcessor,
ConsoleSpanExporter,
SimpleSpanProcessor,
} from "@opentelemetry/sdk-trace-base"
import { pdfCoreFileLayer } from "@signature-kit/pdf-core/file"
import { PdfCore } from "@signature-kit/pdf-core/pdf-core"
import { Effect, Layer } from "effect"
const TracingLive = NodeSdk.layer(() => ({
resource: { serviceName: "contracts-api", serviceVersion: "1.4.0" },
spanProcessor:
process.env.OTEL_EXPORTER_OTLP_ENDPOINT === undefined
? new SimpleSpanProcessor(new ConsoleSpanExporter())
: new BatchSpanProcessor(new OTLPTraceExporter()),
}))
const program = Effect.gen(function* () {
const core = yield* PdfCore
const pdf = new Uint8Array(yield* Effect.promise(() => readFile(process.argv[2] ?? "")))
return (yield* core.text(pdf, { format: "markdown" })).join("\n\n")
}).pipe(Effect.withSpan("contracts.extractMarkdown"))
await Effect.runPromise(
program.pipe(
Effect.provide(
pdfCoreFileLayer.pipe(Layer.provide(NodeServices.layer), Layer.provideMerge(TracingLive)),
),
),
)Run bun tracing.ts contract.pdf to print the spans to the console. Set OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 to send them to a collector, such as Jaeger, Grafana Tempo or the OpenTelemetry Collector, over OTLP/HTTP.
Provide the tracing layer beneath the SignatureKit layers with Layer.provideMerge, not beside them with Layer.mergeAll. Otherwise, spans emitted while a layer is being built, such as pdfCore.load, never reach the exporter.
Span tree
The example above produces this tree:
contracts.extractMarkdown
pdfCore.load signature_kit.wasm.memory_bytes
pdfCore.wasm.instantiate
pdfCore.text signature_kit.pdf.bytes, .page_count, .output_format, .merge_across_pages
pdfCore.wasm.copyIn signature_kit.wasm.input_bytes
pdfCore.wasm.run signature_kit.pdf_core.operation
pdfCore.wasm.decode signature_kit.wasm.result_bytespdfCore.wasm.run covers parsing, layout, table stitching and Markdown rendering inside the Wasm core. The Rust core takes no imports, so it has no clock, and per-page spans would add overhead to the hot path.
Span names follow <scope>.<operation>:
pdfCore.*: PDF engine operations. Lazy documents addpdfCore.lazy.plan,pdfCore.lazy.supplyandpdfCore.readRange.pdf.*: signing in@signature-kit/pdf.pdf.signcontainspdf.placeholder,pdf.byteRange.prepare,pdf.signer.load,pdf.cms.createandpdf.contents.embed. Verification, stamping, merging, anchor search and batch workflows have their own spans.crypto.pkcs12.*,certificates.*,a1.*andsignatures.*: certificate loading, key import, signing and verification.cms.*,xml.*anditi.*: CMS, timestamping, XML-DSig and ITI validation.assinafy.*,clicksign.*,documenso.*,docuseal.*andzapsign.*: remote signature-request lifecycles.HTTP calls are client spans named after the method (
GET,POST). They carryhttp.request.method,http.response.status_code,server.addressandsignature_kit.provider.
Failed operations end with status ERROR and an exception event carrying the tagged error.
What spans never contain
Attributes carry sizes, counts, algorithm and status literals, and provider names. They never contain document text, anchor search strings, certificate subjects or serials, CPF/CNPJ, passwords, keys, digests, signature bytes, upstream request ids, or URLs with paths or query strings.
Promise entry points
@signature-kit/pdf-core/promise and @signature-kit/pdf-core/node run Effect's default tracer, so their spans are never exported. Use the Effect API with the layer above when you need traces.