effect icon indicating copy to clipboard operation
effect copied to clipboard

Unnecessary Frontend Tracing Dependencies (Cannot find module '@opentelemetry/sdk-trace-web')

Open scffs opened this issue 5 months ago • 4 comments

What version of Effect is running?

3.16.12

What steps can reproduce the bug?

add these packages

 "@effect/opentelemetry": "^0.53.13",
 "@opentelemetry/sdk-trace-base": "^2.0.1",
 "@opentelemetry/sdk-trace-node": "^2.0.1",
    "effect": "^3.16.12"

Read the doc and make the same app

https://effect.website/docs/observability/tracing/#tutorial-visualizing-traces


import { Effect } from "effect"
import { NodeSdk } from "@effect/opentelemetry"
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"

// Function to simulate a task with possible subtasks
const task = (
  name: string,
  delay: number,
  children: ReadonlyArray<Effect.Effect<void>> = []
) =>
  Effect.gen(function* () {
    yield* Effect.log(name)
    yield* Effect.sleep(`${delay} millis`)
    for (const child of children) {
      yield* child
    }
    yield* Effect.sleep(`${delay} millis`)
  }).pipe(Effect.withSpan(name))

const poll = task("/poll", 1)

// Create a program with tasks and subtasks
const program = task("client", 2, [
  task("/api", 3, [
    task("/authN", 4, [task("/authZ", 5)]),
    task("/payment Gateway", 6, [
      task("DB", 7),
      task("Ext. Merchant", 8)
    ]),
    task("/dispatch", 9, [
      task("/dispatch/search", 10),
      Effect.all([poll, poll, poll], { concurrency: "inherit" }),
      task("/pollDriver/{id}", 11)
    ])
  ])
])

const NodeSdkLive = NodeSdk.layer(() => ({
  resource: { serviceName: "example" },
  spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter())
}))

Effect.runPromise(
  program.pipe(
    Effect.provide(NodeSdkLive),
    Effect.catchAllCause(Effect.logError)
  )
)

run the app

bun run index.ts

What is the expected behavior?

app is running

(sdk-trace-web is only for web right?)

Image

What do you see instead?

error: Cannot find module '@opentelemetry/sdk-trace-web' from '/Users/sf/WebstormProjects/wallet-analytic/node_modules/@effect/opentelemetry/dist/esm/WebSdk.js'

Additional information

I'm using Bun, and I can't even build the code example.

Image

scffs avatar Jul 12 '25 12:07 scffs

  • Env: Bun 1.2.21, effect 3.16.12, @effect/opentelemetry 0.53.13.
  • Repro: import { NodeSdk } from "@effect/opentelemetry" → bun index.ts → error: cannot find @opentelemetry/sdk-trace-web.
  • Root cause: package root re-exports WebSdk; Bun eagerly resolves re-exports and expects the web peer even in Node.
  • Fix (recommended): import * as NodeSdk from "@effect/opentelemetry/NodeSdk" and install peers: @opentelemetry/resources@^2.1.0 and @opentelemetry/semantic-conventions@^1.33.0.
  • Alt fix: keep root import and install @opentelemetry/sdk-trace-web@^2.0.1 (web-only, installed just to satisfy Bun’s resolver).
  • Note: I hit Resources.emptyResource is not a function with @opentelemetry/[email protected]; pinning to 2.x resolves it.
  • After subpath import + correct peers, the example runs and emits spans.

seanwessmith avatar Sep 12 '25 21:09 seanwessmith

i am having the opposite issue, getting the following error trying to run in a a browser context

[Error] Sync failed: Could not resolve "@opentelemetry/sdk-trace-node" imported by "@effect/opentelemetry". Is it installed?
Error: Could not resolve "@opentelemetry/sdk-trace-node" imported by "@effect/opentelemetry". Is it installed?
__require@http://localhost:1420/node_modules/.vite/deps/chunk-V4OQ3NZ2.js:11:50
module code@http://localhost:1420/node_modules/.vite/deps/@effect_opentelemetry.js:1068:64
	(anonymous function) (SyncFromExternalButton.svelte:20)

justin-prather avatar Oct 21 '25 03:10 justin-prather

@tim-smart or anybody, please check this

scffs avatar Oct 22 '25 01:10 scffs

i was able to get around it by adding @opentelemetry/sdk-trace-node as a dev dependency, but that feels a bit hacky

justin-prather avatar Oct 23 '25 17:10 justin-prather