CodeBlanks Logo Icon CodeBlanks

Distributed

Add distributed tracing and event sourcing.

The distributed tracing layer

In the third lesson we add the distributed tracing layer. OpenTelemetry is the open standard for tracking a request's path across services with a single trace ID. In this project, instead of wiring up the real OpenTelemetry framework, we write a distributedLayer function that represents it.

The distributedLayer function returns { tracing: 'OpenTelemetry', status: 'hazır' }. The output gets a new line OpenTelemetry: hazır. The starting code is appended on top of the setupProject and nativeAddon solutions. This cumulative growth guarantees the correct order when integrationReport later calls all layers. A real OpenTelemetry integration uses the @opentelemetry/node package and HTTP header propagation; here modeling is enough.

The tracing context

A distributed tracing context works with trace ID and span ID. In this project distributedLayer only carries the tracing framework's name; real context propagation comes later. The call pattern still matches the previous layers.

Example: console.log(distributedLayer().tracing + ': ' + distributedLayer().status). This produces the line OpenTelemetry: hazır. The previous lines (ExpertProject, 1.0, N-API: hazır) stay; the new line appends after them. Thanks to cumulative growth, each lesson's output continues the previous one. This ensures that when integrationReport later gathers all layers into one string, every piece lands in the right order.

Practice Add the distributed tracing layer

Take the previous setupProject and nativeAddon solutions. Add function distributedLayer(); return { tracing: 'OpenTelemetry', status: 'hazır' }. Print console.log(distributedLayer().tracing + ': ' + distributedLayer().status).

Starter code

index.js
function setupProject() {
  return { name: 'ExpertProject', version: '1.0' };
}
console.log(setupProject().name);
console.log(setupProject().version);
function nativeAddon() {
  return { api: 'N-API', status: 'hazır' };
}
console.log(nativeAddon().api + ': ' + nativeAddon().status);
// Write the distributedLayer function
// Return an object holding OpenTelemetry tracing info
// Print tracing and status
// write here

Sample solution

index.js
function setupProject() {
  return { name: 'ExpertProject', version: '1.0' };
}
console.log(setupProject().name);
console.log(setupProject().version);
function nativeAddon() {
  return { api: 'N-API', status: 'hazır' };
}
console.log(nativeAddon().api + ': ' + nativeAddon().status);
function distributedLayer() {
  return { tracing: 'OpenTelemetry', status: 'hazır' };
}
console.log(distributedLayer().tracing + ': ' + distributedLayer().status);

Expected output

ExpertProject
1.0
N-API: hazır
OpenTelemetry: hazır

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Match each piece to its role

Term Meaning
OpenTelemetry Tracing standard
distributedLayer Layer function
tracing Tracing name
trace ID Ties the request

2 What does the tracing id do in distributed tracing?

index.js
function distributedLayer() { return {tracing: 'OpenTelemetry', status: 'hazır'}; }
  • A database password
  • Marks the request path Correct answer
  • A user session
  • Only the cache

Explanation: The tracing id marks the request path; it ties all services together.

3 Complete the tracing field

Question
return { tracing: '____', status: 'hazır' };
Answer
return { tracing: 'OpenTelemetry', status: 'hazır' };

Explanation: The tracing field carries 'OpenTelemetry'.

All lessons in Expert