Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Discord: Challenges in Building a Telemetry Layer from an Effect #841

Open
effect-bot opened this issue Sep 17, 2024 · 1 comment
Open

Comments

@effect-bot
Copy link

Summary

Summary

User's Issue:

  • The user is trying to implement OpenTelemetry spans in their Effect app using Azure Insights as the exporter.
  • They wrapped the layer creation in an Effect.try to handle potential errors.
  • They implemented caching using an Option to avoid creating new instances of the telemetry layer on every request.
  • Despite this, the telemetry layer does not seem to work as expected when provided to effects.

Debugging Steps:

  1. Initial Setup:

    • The user created a telemetry layer using Effect.try and cached it using an Option.
    • They provided this layer to effects using Effect.provide.
  2. Observed Behavior:

    • When the telemetry layer is created directly (without effects), it works fine.
    • When created from an effect, the spans do not show up.
  3. Discussion Points:

    • The user noted that the telemetry layer gets created once and reused when using their caching mechanism.
    • They observed that without caching, the layer gets created on every request, which is not desired.
  4. Suggestions:

    • datner_ suggested using ManagedRuntime to ensure the layer is constructed only once and reused across multiple requests.
    • The user implemented ManagedRuntime and found that it resolves the caching issue but the telemetry layer still does not work.
  5. Final Insight:

    • datner_ pointed out that instead of just merging the tracing layer, the entire app should be provided with the tracingLive layer.

Key Takeaways

  1. Layer Memoization:

    • Layers in Effect are memoized, meaning they should only construct once even if composed multiple times.
    • Using ManagedRuntime can ensure that layers are constructed once and reused across multiple requests in a long-lived process.
  2. Providing Layers:

    • When constructing the application layer, ensure that the entire app is provided with the necessary layers (e.g., tracingLive).
  3. Effect Execution:

    • Avoid calling Effect.runPromise repeatedly for short-lived executions. Instead, use a managed runtime to maintain the state of layers.
  4. Debugging Layers:

    • If a layer works when created directly but not when created from an effect, it might indicate an issue with how the layer is being provided or constructed.
  5. Documentation and DX:

    • The experience highlighted potential areas for improving documentation and developer experience, especially around providing layers and using managed runtimes.

Discord thread

https://discord.com/channels/795981131316985866/1285261463610720297

@datner
Copy link
Member

datner commented Sep 17, 2024

TL;DR

'providing' something might need a bit more clarification from a mental model standpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants