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

Disable within a request using modules #17

Open
michaelbrewerdavis opened this issue Feb 24, 2022 · 2 comments
Open

Disable within a request using modules #17

michaelbrewerdavis opened this issue Feb 24, 2022 · 2 comments

Comments

@michaelbrewerdavis
Copy link

I might be missing something, but I don't see a way to use environment variables to disable sending to honeycomb (e.g. for a dev environment).

const honeycombConfig: HoneycombConfig = {}

const module = {
  async fetch(request: Request, env: any, context: ExecutionContext) {
    return await handleRequest(request, env);
  },
};

export default wrapModule(honeycombConfig, module);

As I undestand it, modules put environment variables in the env argument, so they're not accessible at the time of wrapModule(). The ability to specify HONEYCOMB_DATASET and HONEYCOMB_API_KEY as env vars means we don't end up adding data, but we do still end up making requests to honeycomb.

A couple possibilities:

  • add an env var to disable
  • add a config key to disable and
    -- merge env with HoneycombConfig as we resolve configs, or
    -- make more config keys overridable with env vars
@ptim
Copy link

ptim commented Apr 29, 2022

Here's what I'm doing (feedback welcome!)

const module = {
  async fetch(request: Request, env: any, context: ExecutionContext) {
    request.tracer.addData({ env: env.ENVIRONMENT })
    return await handleRequest(request, env);
  },
};

const honeycombConfig: Partial<ResolvedConfig> = {
  dataset: 'main',
  sampleRates(data: any): number {
    if (data.response.ok === true) {
      // `request.tracer.addData` provides `data.env`
      return data.env === 'production' ? 4 : 1
    } else {
      return 1
    }
  },
}
export default wrapModule(honeycombConfig, handler)

wrangler.toml:

# ...
[env.staging.vars]
ENVIRONMENT = "staging"

(alternatively, you could inject env vars using esbuild / webpack, etc)

@evanderkoogh
Copy link
Contributor

That is a very smart and ugly hack @ptim.. and I am sorry for you having to type that :)

I will change the behaviour so that if no api key or dataset is provided, it just won't send..

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

3 participants