Skip to content

Instantiate a RootSpanContextManager and save it on CrashlyticsService#9890

Open
rebehe wants to merge 1 commit intocrashlytics-tracesfrom
context-manager-direct-instantiation
Open

Instantiate a RootSpanContextManager and save it on CrashlyticsService#9890
rebehe wants to merge 1 commit intocrashlytics-tracesfrom
context-manager-direct-instantiation

Conversation

@rebehe
Copy link
Copy Markdown

@rebehe rebehe commented Apr 24, 2026

This is the more Firebase idiomatic way to address the "multiple context managers" issue and ultimately replaces the global singleton approach. This works because _registerComponent is a factory function and is guaranteed to be called once. When we save the RootSpanContextManager object reference on CrashlyticsService, all module callers of RootSpanContextManager will end up with the same instance.

@rebehe rebehe requested a review from a team as a code owner April 24, 2026 15:25
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 303a12a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Crashlytics service to support multi-app isolation by replacing the global rootSpanContextManager with per-instance managers. The changes include updating the CrashlyticsService constructor, registration logic, and helper functions to utilize the instance-specific context manager. A review comment identifies a type inconsistency where tracingProvider is marked as nullable in the service constructor but non-nullable in the internal interface, which could lead to runtime issues.

public app: FirebaseApp,
public loggerProvider: LoggerProvider,
public tracingProvider: TracerProvider | null
public tracingProvider: TracerProvider | null,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The tracingProvider is marked as nullable (TracerProvider | null) here, but the CrashlyticsInternal interface in types.ts defines it as non-nullable. This inconsistency can lead to runtime errors when the service is cast to CrashlyticsInternal and tracingProvider is accessed without a null check, as seen in helpers.ts. If the provider is guaranteed to be present (which is the case in the registration factories), the type should be made non-nullable here as well.

Suggested change
public tracingProvider: TracerProvider | null,
public tracingProvider: TracerProvider,

@rebehe rebehe force-pushed the trace-boundaries-react-router branch from a02fe22 to f5e0a97 Compare April 24, 2026 15:29
Base automatically changed from trace-boundaries-react-router to crashlytics-traces April 24, 2026 15:29
This is the more Firebase idiomatic way to address the "multiple context managers" issue and ultimately replaces the global singleton approach. This works because _registerComponent is a factory function and is guaranteed to be called once. When we save the RootSpanContextManager object reference on CrashlyticsService, all module callers of RootSpanContextManager will end up with the same instance.
@rebehe rebehe force-pushed the context-manager-direct-instantiation branch from b5032ba to 303a12a Compare April 24, 2026 21:04
ExportResult,
W3CTraceContextPropagator
} from '@opentelemetry/core';
import { TracerProvider, trace, context } from '@opentelemetry/api';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove unused context import

import { CrashlyticsService } from './service';
import { CrashlyticsInternal } from './types';
import { rootSpanContextManager } from './tracing/root-span-context-manager';
import { RootSpanContextManager } from './tracing/root-span-context-manager';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove if unused

*/
export function startNewSession(crashlytics: Crashlytics): void {
// Cast to CrashlyticsInternal to access internal loggerProvider
const { loggerProvider, tracingProvider } =
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove tracingProvider if unsused

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

Successfully merging this pull request may close these issues.

2 participants