Skip to content

Commit ab6e911

Browse files
committed
Enhance friendly name
1 parent 3f3827b commit ab6e911

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

sdk/@launchdarkly/observability-react-native/src/api/Options.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ export interface ReactNativeOptions {
8787
* ```ts
8888
* contextFriendlyName: (context: LDContext) => {
8989
* if(context.kind === 'multi' && context.user?.email) {
90-
* return `context.user.email`;
90+
* return context.user.email;
91+
* } else if(context.kind === 'user') {
92+
* return context.key;
9193
* }
92-
* return context.key;
94+
* // Use the default identifier for contexts which don't contain a user.
95+
* return undefined;
9396
* }
9497
* ```
9598
* @param context The context to get a friendly name for.
96-
* @returns The friendly name for the context.
99+
* @returns The friendly name for the context, or undefined to use the
100+
* default identifier.
97101
*/
98-
contextFriendlyName?: (context: LDContext) => string
102+
contextFriendlyName?: (context: LDContext) => string | undefined
99103
}

sdk/@launchdarkly/observability-react-native/src/plugin/observability.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ import {
4040
class TracingHook implements Hook {
4141
private metaAttributes: Attributes = {}
4242

43-
constructor(private metadata: LDPluginEnvironmentMetadata) {
43+
constructor(
44+
private metadata: LDPluginEnvironmentMetadata,
45+
private readonly _options: ReactNativeOptions,
46+
) {
4447
this.metaAttributes = {
4548
[ATTR_TELEMETRY_SDK_NAME]:
4649
'@launchdarkly/observability-react-native',
@@ -66,7 +69,7 @@ class TracingHook implements Hook {
6669
...this.metaAttributes,
6770
...getCanonicalObj(hookContext.context),
6871
key:
69-
this.options?.contextFriendlyName?.(hookContext.context) ??
72+
this._options?.contextFriendlyName?.(hookContext.context) ??
7073
getCanonicalKey(hookContext.context),
7174
canonicalKey: getCanonicalKey(hookContext.context),
7275
timeout: hookContext.timeout,
@@ -163,6 +166,6 @@ export class Observability implements LDPlugin {
163166
}
164167

165168
getHooks?(metadata: LDPluginEnvironmentMetadata): Hook[] {
166-
return [new TracingHook(metadata)]
169+
return [new TracingHook(metadata, this._options)]
167170
}
168171
}

sdk/highlight-run/src/client/types/observe.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ export type ObserveOptions = CommonOptions & {
7575
* ```ts
7676
* contextFriendlyName: (context: LDContext) => {
7777
* if(context.kind === 'multi' && context.user?.email) {
78-
* return `context.user.email`;
78+
* return context.user.email;
79+
* } else if(context.kind === 'user') {
80+
* return context.key;
7981
* }
80-
* return context.key;
82+
* // Use the default identifier for contexts which don't contain a user.
83+
* return undefined;
8184
* }
8285
* ```
8386
* @param context The context to get a friendly name for.
84-
* @returns The friendly name for the context.
87+
* @returns The friendly name for the context, or undefined to use the
88+
* default identifier.
8589
*/
86-
contextFriendlyName?: (context: LDContext) => string
90+
contextFriendlyName?: (context: LDContext) => string | undefined
8791
}

0 commit comments

Comments
 (0)