Git Product home page Git Product logo

Comments (2)

Flarna avatar Flarna commented on June 15, 2024

It's not really a context loss here. This is a limitation of how request attributes are attached to a trace.

As of now request attributes can be only attached to an open request. Once you send the 202 response the web request trace entry is ended and as a result the request attribute can't be attached anymore.
In contrast to request attributes other children like DB, HTTP or messaging requests (even when done via SDK) create a new linked entry in the trace but that's currently not supported for request attributes.

However, request attributes can be attached to this children and they are propagated up to the web request. But again they have to be added when the request is still ongoing.

Here is a small sample to illustrate this:

import * as http from "http";
import { createInstance } from "@dynatrace/oneagent-sdk";

const sdk = createInstance();
sdk.setLoggingCallbacks({
  error(msg) { console.log("sdk error:", msg) },
  warning(msg) { console.log("sdk warn:", msg) }
});

http.createServer((req, res) => {
  sdk.addCustomRequestAttribute("onRequest", "works");
  res.statusCode = 202;
  res.end();
  sdk.addCustomRequestAttribute("afterEnd sync in handler", "works");

  setImmediate(() => {
    sdk.addCustomRequestAttribute("afterEnd async", "works not");

    http.get("http://example.org", (cltRsp) => {
      cltRsp.resume();
      sdk.addCustomRequestAttribute("inCltCb", "works again as in a sync callback");
    });
  });
}).listen(8100);

The SDK log attribute <afterEnd async> not added because no active trace context found is a bit misleading here. A better wording would be probably attribute <afterEnd async> not added because no transaction is active.

fyi @z1c0

from oneagent-sdk-for-nodejs.

Flarna avatar Flarna commented on June 15, 2024

I will close this issue. Feel free to reopen in case you have more questions regarding this.

from oneagent-sdk-for-nodejs.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.