Cloud platforms
Questions about AWS, Azure, and Google Cloud Platform.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GCP functions (Node.js) integration with Dynatrace

annam
Frequent Guest

Hello experts, 

I'm learning how to integrate GCP function traces with Dynatrace documentation for Node.js: 

1.Set up OpenTelemetry monitoring for Google Cloud Functions — Dynatrace Docs

2. Integrate on Google Cloud Functions Node.js — Dynatrace Docs

Sadly, I can't get the traces on Dynatrace's side using the doc samples for the code:

 

index.js (where helloHttp is my entry function):

const functions = require('@google-cloud/functions-framework');

const { Resource } = require('@opentelemetry/resources');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { DtSpanExporter, DtSpanProcessor, DtTextMapPropagator, DtSampler } = require('@dynatrace/opentelemetry-gcf');

const processor = new DtSpanProcessor(new DtSpanExporter());
const provider = new NodeTracerProvider({
  resource: new Resource({
   "my.resource.attribute": "My Resource",
  }),
  sampler: new DtSampler(),
  // for @opentelemetry/sdk-trace-node versions lower than 1.29.0 use `provider.addSpanProcessor(processor)` instead
  spanProcessors: [processor]
  // ...other configurations
});

provider.register({
  propagator: new DtTextMapPropagator(),
  // ...other configurations
});


/////////////

// ...tracing initialization code

const { startActiveHttpSpan, endHttpSpanAndFlush } = require('@dynatrace/opentelemetry-gcf');

// ...tracing initialization code

async function handler(req, res) {
  await startActiveHttpSpan(req, async (span) => {
    let error;
    try {
      // do something
      console.log("Hello Console...")
    } catch (e) {
      error = e;
    }

    // status should be set before span ends
    res.status(error != null ? 500 : 200);
    /**
     * Span must be ended and flushed before handler sends response.
     * This limitiation comes from GCF, for details see:
     * https://cloud.google.com/functions/docs/concepts/nodejs-runtime#signal-termination
     */
    await endHttpSpanAndFlush(span, res, error);
    res.send("hello world!");
  });
}

/////////////

functions.http('helloHttp', (req, res) => {
    handler(req,res);
});

 

I ran the same test with a Python function, and it worked without issues, which makes me think my code has an issue. 

 

Thank you in advance for any comment or recommendation; it is well appreciated.

0 REPLIES 0

Featured Posts