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

How do I use toucan-js with Sentry Performance/Tracing #101

Open
STRRL opened this issue Jul 19, 2022 · 3 comments
Open

How do I use toucan-js with Sentry Performance/Tracing #101

STRRL opened this issue Jul 19, 2022 · 3 comments

Comments

@STRRL
Copy link

STRRL commented Jul 19, 2022

Hi! I want to use toucan-js for collecting tracing data with my cloudflare workers application.

I have set up the tracesSampleRate when new Toucan({<options>}), but it does not work, no data on the sentry performance panel appeared.

What should I do to use toucan with tracing correctly?

Thank in advance!

@ngshiheng
Copy link

hey @STRRL , I'm not the maintainer of toucan-js but I encountered the same issue when I didn't import @sentry/tracing. Here's an example:

import { Toucan } from 'toucan-js';
import '@sentry/tracing';


type Env = {
	SENTRY_DSN: string;
};

export default {
	async fetch(request, env, context): Promise<Response> {
		const sentry = new Toucan({
			dsn: env.SENTRY_DSN,
			tracesSampleRate: 1.0,
			context,
			request,
		});

		const transaction = sentry.startTransaction({ name: 'someRandomName' });
		try {
			handler();
			return new Response('Hello!');
		} catch (e) {
			sentry.captureException(e);

			return new Response('Something went wrong! Team has been notified.', {
				status: 500,
			});
		} finally {
			transaction.finish();
		}
	},
} as ExportedHandler<Env>;

To create a span, simply do const span = transaction.startChild({ op: 'someFunction' });. Just remember to call span.finish() at the end of it.

@mikkoh
Copy link

mikkoh commented Feb 27, 2023

One thing I'll add to @ngshiheng's answer is that you need to pass a description to give a name for the span:

const span = transaction.startChild({
    op: 'timeout 1',
    description: 'Timeout 1',
  });

Screenshot 2023-02-27 at 9 35 07 AM

(unnamed span) is what you get when you don't pass a description

@jahands
Copy link

jahands commented Oct 20, 2024

Anyone figured out how to use tracing in toucan-js 4? Looks like things have changed quite a bit

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

4 participants