De Logboek Dataverwerkingen-implementatie is gebaseerd op de standaard van OpenTelemetry. Onderstaand zijn voorbeelden in verschillende programmeertalen om verwerkingen van persoonsgegevens te loggen.
package main
import (
"context"
"log"
"time"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
func main() {
ctx := context.Background()
exporter, err := otlptracegrpc.New(ctx,
otlptracegrpc.WithEndpointURL("https://example.com/"),
)
if err != nil {
log.Fatalf("error creating exporter: %v", err)
}
// // Alternative for testing purposes: create a stdout exporter
// exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
// if err != nil {
// log.Fatalf("failed to initialize stdouttrace exporter: %v", err)
// }
// Create a new tracer provider with the exporter
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
)
defer func() { tp.Shutdown(ctx) }()
// Set the global tracer provider
otel.SetTracerProvider(tp)
// Create a tracer
tracer := otel.Tracer("organization-id/service-name")
// Set the span attributes (BSN and activity ID)
opts := []trace.SpanStartOption{
trace.WithTimestamp(time.Now()),
trace.WithAttributes(
attribute.String("dpl.core.user", "111222333"),
attribute.String("dpl.rva.activity.id", "activity-id"),
),
}
// // Optional: add foreign trace context
// opts = append(opts, trace.WithAttributes(
// attribute.String("dpl.rva.foreign.trace_id", "parent-trace-id"),
// attribute.String("dpl.rva.foreign.operation_id", "parent-operation-id"),
// ))
// Start a new span
_, span := tracer.Start(ctx, "operation-id", opts...)
defer span.End()
// Simulate some work
time.Sleep(100 * time.Millisecond)
// Set the status of the span
span.SetStatus(codes.Ok, "")
}
import { context, trace, SpanStatusCode, diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { WebTracerProvider, BatchSpanProcessor } from '@opentelemetry/sdk-trace-web';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { Resource } from '@opentelemetry/resources';
// Set up diagnostic logging
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
// Create a new tracer provider
const provider = new WebTracerProvider({
resource: new Resource({
'service.name': 'organization-id/service-name',
}),
});
// Create an OTLP trace exporter
const exporter = new OTLPTraceExporter({
url: 'https://example.com/',
});
// Add the exporter to the provider
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
// Register the provider as the global tracer provider
provider.register();
// Get a tracer
const tracer = trace.getTracer('organization-id/service-name');
// Create a context
const ctx = context.active();
// Set the span attributes (BSN and activity ID)
const attributes = {
'dpl.core.user': '111222333',
'dpl.rva.activity.id': 'activity-id',
// // Optional: add foreign trace context
// 'dpl.rva.foreign.trace_id': 'parent-trace-id',
// 'dpl.rva.foreign.operation_id': 'parent-operation-id',
};
// Start a new span
const span = tracer.startSpan('operation-id', {
startTime: Date.now(),
attributes,
}, ctx);
// Simulate some work
setTimeout(() => {
// Set the status of the span
span.setStatus({ code: SpanStatusCode.OK });
// End the span
span.end();
}, 100);
import time
import logging
from opentelemetry import trace, context
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.trace import SpanKind
from opentelemetry.sdk.resources import Resource
from opentelemetry.trace.status import Status, StatusCode
# Set up logging
logging.basicConfig(level=logging.INFO)
# Create an OTLP trace exporter
exporter = OTLPSpanExporter(endpoint="https://example.com/")
# Create a new tracer provider with the exporter
provider = TracerProvider(resource=Resource.create({
"service.name": "organization-id/service-name"
}))
provider.add_span_processor(BatchSpanProcessor(exporter))
# Set the global tracer provider
trace.set_tracer_provider(provider)
# Get a tracer
tracer = trace.get_tracer("organization-id/service-name")
# Create a context
ctx = context.get_current()
# Set the span attributes (BSN and activity ID)
attributes = {
"dpl.core.user": "111222333",
"dpl.rva.activity.id": "activity-id",
# # Optional: add foreign trace context
# "dpl.rva.foreign.trace_id": "parent-trace-id",
# "dpl.rva.foreign.operation_id": "parent-operation-id",
}
# Start a new span
with tracer.start_as_current_span("operation-id", context=ctx, kind=SpanKind.INTERNAL, attributes=attributes) as span:
# Simulate some work
time.sleep(0.1)
# Set the status of the span
span.set_status(Status(StatusCode.OK))
# Shutdown the tracer provider
provider.shutdown()
Voor andere programmeertalen, zie de documentatie van de OpenTelemetry SDKs.