8000 Fix build (uses yalc for scope changes) and use LRUMap util · benjick/sentry-javascript@91a4db9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91a4db9

Browse files
committed
Fix build (uses yalc for scope changes) and use LRUMap util
1 parent bd04755 commit 91a4db9

File tree

11 files changed

+134
-24
lines changed

11 files changed

+134
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"packages/gatsby",
6464
"packages/google-cloud-serverless",
6565
"packages/integration-shims",
66+
"packages/launchdarkly",
6667
"packages/nestjs",
6768
"packages/nextjs",
6869
"packages/node",

packages/core/src/scope.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ import type {
2222
SeverityLevel,
2323
User,
2424
} from '@sentry/types';
25-
import { dateTimestampInSeconds, generatePropagationContext, isPlainObject, logger, uuid4 } from '@sentry/utils';
25+
import {
26+
LRUMap,
27+
dateTimestampInSeconds,
28+
generatePropagationContext,
29+
isPlainObject,
30+
logger,
31+
uuid4,
32+
} from '@sentry/utils';
2633

2734
import { updateSession } from './session';
2835
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
@@ -99,7 +106,7 @@ class ScopeClass implements ScopeInterface {
99106
protected _lastEventId?: string;
100107

101108
/** LRU cache of flags last evaluated by a feature flag provider. Used by FF integrations. */
102-
protected _flagBuffer: FeatureFlag[];
109+
protected _flagBuffer: LRUMap<FeatureFlag['flag'], FeatureFlag['result']>;
103110

104111
/** Max size of the flagBuffer */
105112
protected _flagBufferSize: number; // TODO: make const?
@@ -119,8 +126,8 @@ class ScopeClass implements ScopeInterface {
119126
this._sdkProcessingMetadata = {};
120127
this._propagationContext = generatePropagationContext();
121128

122-
this._flagBuffer = [];
123129
this._flagBufferSize = 100;
130+
this._flagBuffer = new LRUMap<FeatureFlag['flag'], FeatureFlag['result']>(this._flagBufferSize);
124131
}
125132

126133
/**
@@ -513,30 +520,18 @@ class ScopeClass implements ScopeInterface {
513520
* @inheritDoc
514521
*/
515522
public getFlags(): FeatureFlag[] {
516-
return this._flagBuffer || [];
523+
const flags: FeatureFlag[] = [];
524+
this._flagBuffer.keys().forEach(key => {
525+
flags.push({ flag: key, result: this._flagBuffer.get(key) as boolean });
526+
});
527+
return flags;
517528
}
518529

519530
/**
520531
* @inheritDoc
521532
*/
522533
public insertFlag(name: string, value: boolean): void {
523-
// Check if the flag is already in the buffer
524-
const index = this._flagBuffer.findIndex(f => f.flag === name);
525-
526-
if (index !== -1) {
527-
// Delete flag if it is in the buffer
528-
this._flagBuffer.splice(index, 1);
529-
} else if (this._flagBuffer.length === this._flagBufferSize) {
530-
// If at capacity, we need to remove the earliest flag (pop from front)
531-
// This will only happen if not a duplicate flag
532-
this._flagBuffer.shift();
533-
}
534-
535-
// Push the flag to the end of the queue
536-
this._flagBuffer.push({
537-
flag: name,
538-
result: value,
539-
});
534+
this._flagBuffer.set(name, value);
540535
}
541536

542537
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2024 Functional Software, Inc. dba Sentry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<p align="center">
2+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4+
</a>
5+
</p>
6+
7+
# Sentry JavaScript SDK Types
8+
9+
[![npm version](https://img.shields.io/npm/v/@sentry/types.svg)](https://www.npmjs.com/package/@sentry/types)
10+
[![npm dm](https://img.shields.io/npm/dm/@sentry/types.svg)](https://www.npmjs.com/package/@sentry/types)
11+
[![npm dt](https://img.shields.io/npm/dt/@sentry/types.svg)](https://www.npmjs.com/package/@sentry/types)
12+
13+
## Links
14+
15+
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
16+
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
17+
18+
## General
19+
20+
Common types used by the Sentry JavaScript SDKs.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@sentry/types",
3+
"version": "8.35.0+76139869",
4+
"description": "Types for all Sentry JavaScript SDKs",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/types",
7+
"author": "Sentry",
8+
"license": "MIT",
9+
"engines": {
10+
"node": ">=14.18"
11+
},
12+
"files": [
13+
"/build"
14+
],
15+
"main": "build/cjs/index.js",
16+
"module": "build/esm/index.js",
17+
"types": "build/types/index.d.ts",
18+
"exports": {
19+
"./package.json": "./package.json",
20+
".": {
21+
"import": {
22+
"types": "./build/types/index.d.ts",
23+
"default": "./build/esm/index.js"
24+
},
25+
"require": {
26+
"types": "./build/types/index.d.ts",
27+
"default": "./build/cjs/index.js"
28+
}
29+
}
30+
},
31+
"typesVersions": {
32+
"<4.9": {
33+
"build/types/index.d.ts": [
34+
"build/types-ts3.8/index.d.ts"
35+
]
36+
}
37+
},
38+
"publishConfig": {
39+
"access": "public"
40+
},
41+
"scripts": {
42+
"build": "run-p build:transpile build:types",
43+
"build:dev": "yarn build",
44+
"build:transpile": "rollup -c rollup.npm.config.mjs",
45+
"build:types": "run-s build:types:core build:types:downlevel",
46+
"build:types:core": "tsc -p tsconfig.types.json",
47+
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
48+
"build:watch": "run-p build:transpile:watch build:types:watch",
49+
"build:dev:watch": "yarn build:watch",
50+
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
51+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
52+
"build:tarball": "npm pack",
53+
"clean": "rimraf build sentry-types-*.tgz",
54+
"lint": "eslint . --format stylish",
55+
"fix": "eslint . --format stylish --fix",
56+
"yalc:publish": "yalc publish --push --sig"
57+
},
58+
"volta": {
59+
"extends": "../../package.json"
60+
},
61+
"sideEffects": false,
62+
"yalcSig": "761398697aa19d98ec1c2085192f95dc"
63+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
761398697aa19d98ec1c2085192f95dc

packages/launchdarkly/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@sentry/browser": "^8.35.0",
4343
"@sentry/core": "8.35.0",
44-
"@sentry/types": "8.35.0",
44+
"@sentry/types": "file:.yalc/@sentry/types",
4545
"@sentry/utils": "8.35.0",
4646
"launchdarkly-js-client-sdk": "^3.5.0"
4747
},

packages/launchdarkly/src/core/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as Sentry from '@sentry/browser';
44
import type { Client as SentryClient, Event, EventHint, IntegrationFn } from '@sentry/types';
55
import type { LDContext, LDEvaluationDetail, LDInspectionFlagUsedHandler } from 'launchdarkly-js-client-sdk';
6-
import type { LaunchDarklyOptions } from './types';
6+
import type { LaunchDarklyOptions } from '../types';
77

88
/**
99
* Sentry integration for capturing feature flags from LaunchDarkly.

packages/launchdarkly/yalc.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "v1",
3+
"packages": {
4+
"@sentry/types": {
5+
"signature": "761398697aa19d98ec1c2085192f95dc",
6+
"file": true,
7+
"replaced": "8.35.0"
8+
}
9+
}
10+
}

packages/types/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,3 @@ export type {
174174
export type { ParameterizedString } from './parameterize';
175175
export type { ContinuousProfiler, ProfilingIntegration, Profiler } from './profiling';
176176
export type { ViewHierarchyData, ViewHierarchyWindow } from './view-hierarchy';
177-
export type { FeatureFlag } from './flags';

0 commit comments

Comments
 (0)
0