Skip to content

Root span doesn't end when the request throws error, triggering a custom onError handler. #56

@Juno-T

Description

@Juno-T

What version of Elysia is running?

1.4.13

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

Create Elysia app like below, with any otel instrumentation

const app = new Elysia({ adapter: node() })
  .use(instrumentation)
  .onError(({ error }) => {
    console.log(error);
    return {
      error: error,
    };
  })
  // works fine
  .get("/", () => {
    return "Hello Elysia";
  })
  // No root span
  .get("/error", () => {
    throw new Error("Error");
  })
  .listen(3000)

And then try requesting /error. You should see a trace with child spans, but not root span.

What is the expected behavior?

The root span is sent and shown in the trace viewer.

What do you see instead?

Grafana Tempo shows: <root span not yet received> at the trace. Though, the child spans are logged properly. They all have parent root span id property, but the root span isn't there.

Additional information

A workaround:

I tried manually update the elysia's opentelemetry function by copying whatever inside onAfterResponse into onError callback and it solved the problem.

Fail

Image

Pass (using my workaround)

Image

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions