Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ const client = createFlaggr({ serviceId: 'web-app', apiKey: 'fgr_xxx', exposeFla
data-api-url="https://api.flaggr.dev" data-expose-flags="false" defer></script>
```

## Error tracking

```ts
import { createFlaggr, flaggrErrors, captureException } from "@flaggr/sdk";

createFlaggr({ serviceId: "web-app", apiKey: "fgr_...", plugins: [flaggrErrors({ release: "web@1.4.2" })] });
captureException(error, { tags: { step: "pay" } });
```

Uncaught errors are reported automatically, with the flag variants the client evaluated and the breadcrumbs that led up to them. They show up as issues in the Flaggr console. On a server, set `FLAGGR_ERRORS_TOKEN` (or `serverToken`) to a project API token. See [Error Tracking](https://flaggr.dev/docs/sdk/typescript-sdk#error-tracking).

## OpenTelemetry

```typescript
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flaggr/sdk",
"version": "0.5.0",
"version": "0.6.0",
"description": "Flaggr feature flag SDK for TypeScript \u2014 type-safe evaluation with pluggable OpenTelemetry instrumentation",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
19 changes: 17 additions & 2 deletions packages/sdk/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* </script>
*/

import { configure, flaggrTelemetry } from "./index";
import { configure, flaggrErrors, flaggrTelemetry } from "./index";
import { getGlobalClient } from "./global";
import { recordOptOut } from "./expose-flags";
import type { FlaggrConfig, UpdateMode } from "./types";

Expand All @@ -20,6 +21,11 @@ export {
resetGlobalClient,
flag,
flaggrTelemetry,
flaggrErrors,
captureException,
captureMessage,
addBreadcrumb,
setUser,
} from "./index";

/**
Expand All @@ -31,7 +37,8 @@ export {
* <script>await flaggr.flag("checkout-v2", false)</script>
*
* Optional: data-api-url (default https://api.flaggr.dev), data-environment,
* data-update-mode, data-remote-config, data-telemetry.
* data-update-mode, data-remote-config, data-telemetry, data-errors (error
* tracking, with data-release naming your app's version).
*/
if (typeof document !== "undefined") {
// data-expose-flags="false" on any script tag now keeps flag values off
Expand All @@ -58,12 +65,20 @@ if (typeof document !== "undefined") {
// data-telemetry → attach the telemetry plugin (eval stats + Web Vitals
// + error correlation, beacon-flushed to the platform)
if (tag.dataset.telemetry !== undefined) config.plugins = [flaggrTelemetry()];
// data-errors → error tracking (flaggrErrors), data-release its release.
const trackErrors = tag.dataset.errors !== undefined && tag.dataset.errors !== "false";
if (trackErrors) {
config.plugins = [...(config.plugins ?? []), flaggrErrors(tag.dataset.release ? { release: tag.dataset.release } : {})];
}
// data-expose-flags="false" (on this or any script tag) keeps flag
// values off the page. It isn't passed here: every client reads it
// from the page (and recordOptOut above), so it still applies after a
// later configure() and to createFlaggr() clients (see shouldExpose in
// expose-flags.ts).
configure(config);
// The global client is made at the first flaggr.flag(); errors before
// then would be missed, so error tracking makes it now.
if (trackErrors) getGlobalClient();
}
}

Expand Down
Loading
Loading