Skip to content
Open
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
24 changes: 16 additions & 8 deletions packages/client/react-base/src/logger/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import * as datadogLogger from "@datadog/browser-logs";
* Should be called once when the SDK is initialized (typically in CrossmintProvider)
* This handles browser-specific Datadog sink initialization
* @param apiKey - API key to determine environment (development/staging/production) and project ID
* @param loggingConsent - Whether the user has consented to logging. If false, the logger will not be initialized with Datadog sinks.
* @returns The initialized logger instance
*/
export function initReactLogger(apiKey: string, packageName: string, packageVersion: string): SdkLogger {
export function initReactLogger(
apiKey: string,
packageName: string,
packageVersion: string,
loggingConsent?: boolean
): SdkLogger {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
throw new Error(`Invalid API key: ${validationResult.message}`);
Expand All @@ -21,13 +27,15 @@ export function initReactLogger(apiKey: string, packageName: string, packageVers
projectId,
});

const platform = detectPlatform();
if (platform === "browser") {
const sink = new BrowserDatadogSink(environment, datadogLogger);
logger.addSink(sink);
} else if (platform === "server") {
const sink = new ServerDatadogSink(environment);
logger.addSink(sink);
if (loggingConsent === true) {
const platform = detectPlatform();
if (platform === "browser") {
const sink = new BrowserDatadogSink(environment, datadogLogger);
logger.addSink(sink);
} else if (platform === "server") {
const sink = new ServerDatadogSink(environment);
logger.addSink(sink);
}
}

return logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export function CrossmintProvider({
appId,
extensionId,
overrideBaseUrl,
loggingConsent,
}: CrossmintConfig & {
children: ReactNode;
}) {
const logger = useMemo(() => {
return initReactLogger(apiKey, packageJson.name, packageJson.version);
}, [apiKey]);
return initReactLogger(apiKey, packageJson.name, packageJson.version, loggingConsent);
}, [apiKey, loggingConsent]);

const [version, setVersion] = useState(0);
const crossmintRef = useRef<Crossmint | null>(null);
Expand Down
25 changes: 14 additions & 11 deletions packages/client/ui/react-native/src/logger/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export async function initializeDatadog(options: InitializeDatadogOptions): Prom
* Should be called once when the SDK is initialized (typically in CrossmintProvider)
* This handles React Native-specific Datadog sink initialization
* @param apiKey - API key to determine environment (development/staging/production) and project ID
* @param loggingConsent - Whether the user has consented to logging. If false, the logger will not be initialized with Datadog sinks.
* @returns The initialized logger instance
*/
export function initReactNativeLogger(apiKey: string): SdkLogger {
export function initReactNativeLogger(apiKey: string, loggingConsent?: boolean): SdkLogger {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
throw new Error(`Invalid API key: ${validationResult.message}`);
Expand All @@ -62,17 +63,19 @@ export function initReactNativeLogger(apiKey: string): SdkLogger {
platform: "react-native",
});

const isExpoGo =
Constants.executionEnvironment === "storeClient" ||
Constants.appOwnership === "expo" ||
!!Constants.expoVersion;
if (loggingConsent === true) {
const isExpoGo =
Constants.executionEnvironment === "storeClient" ||
Constants.appOwnership === "expo" ||
!!Constants.expoVersion;

initializeDatadog({
environment,
isExpoGo,
});
const sink = new ReactNativeDatadogSink(environment, datadogReactNativeModule);
logger.addSink(sink);
initializeDatadog({
environment,
isExpoGo,
});
const sink = new ReactNativeDatadogSink(environment, datadogReactNativeModule);
logger.addSink(sink);
}

return logger;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export function CrossmintProvider({
children,
apiKey,
overrideBaseUrl,
}: Pick<CrossmintConfig, "apiKey" | "overrideBaseUrl"> & {
loggingConsent,
}: Pick<CrossmintConfig, "apiKey" | "overrideBaseUrl" | "loggingConsent"> & {
children: ReactNode;
}) {
const logger = useMemo(() => {
return initReactNativeLogger(apiKey);
}, [apiKey]);
return initReactNativeLogger(apiKey, loggingConsent);
}, [apiKey, loggingConsent]);

// Get app ID from Expo constants
const appId = Constants.expoConfig?.ios?.bundleIdentifier ?? Constants.expoConfig?.android?.package;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { useMemo, type ReactNode } from "react";

export const LoggerContext = createLoggerContext();

export function CrossmintProvider({ apiKey, ...props }: CrossmintConfig & { children: ReactNode }) {
export function CrossmintProvider({ apiKey, loggingConsent, ...props }: CrossmintConfig & { children: ReactNode }) {
const logger = useMemo(() => {
return initReactLogger(apiKey, packageJson.name, packageJson.version);
}, [apiKey]);
return initReactLogger(apiKey, packageJson.name, packageJson.version, loggingConsent);
}, [apiKey, loggingConsent]);
return (
<LoggerContext.Provider value={logger}>
<BaseCrossmintProvider apiKey={apiKey} {...props} />
<BaseCrossmintProvider apiKey={apiKey} loggingConsent={loggingConsent} {...props} />
</LoggerContext.Provider>
);
}
4 changes: 3 additions & 1 deletion packages/common/base/src/types/Crossmint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type CrossmintConfig = {
appId?: string;
extensionId?: string;
experimental_customAuth?: CustomAuth;
loggingConsent?: boolean;
};

export type Crossmint = CrossmintConfig & {
Expand All @@ -33,7 +34,7 @@ export function createCrossmint(
config: CrossmintConfig,
apiKeyExpectations?: ValidateAPIKeyPrefixExpectations
): Crossmint {
const { apiKey, jwt, overrideBaseUrl, appId, extensionId, experimental_customAuth } = config;
const { apiKey, jwt, overrideBaseUrl, appId, extensionId, experimental_customAuth, loggingConsent } = config;
const apiKeyValidationResult = validateAPIKey(apiKey, apiKeyExpectations);
if (!apiKeyValidationResult.isValid) {
throw new Error(apiKeyValidationResult.message);
Expand All @@ -54,6 +55,7 @@ export function createCrossmint(
appId,
extensionId,
experimental_customAuth,
loggingConsent,
experimental_setCustomAuth,
setJwt,
};
Expand Down
47 changes: 25 additions & 22 deletions packages/wallets/src/logger/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export const walletsLogger = new SdkLogger();
* Should be called once when the SDK is initialized
* Automatically detects the platform and environment from API key
* @param apiKey - Optional API key to determine environment (development/staging/production)
* @param loggingConsent - Whether the user has consented to logging. If false, the logger will not be initialized with Datadog sinks.
*/
export function initWalletsLogger(apiKey: string): void {
export function initWalletsLogger(apiKey: string, loggingConsent?: boolean): void {
const platform = detectPlatform();
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
Expand All @@ -35,27 +36,29 @@ export function initWalletsLogger(apiKey: string): void {
platform,
});

// Add platform-specific Datadog sink
switch (platform) {
case "browser": {
const sink = new BrowserDatadogSink(environment, datadogLogger);
walletsLogger.addSink(sink);
break;
}
case "react-native": {
// React Native logger initialization is handled by @crossmint/client-sdk-react-native-ui
// This package only initializes for browser/server to avoid bundling React Native dependencies
// The React Native UI package will initialize the logger with the appropriate Datadog sink
break;
}
case "server": {
const sink = new ServerDatadogSink(environment);
walletsLogger.addSink(sink);
break;
}
default: {
// Unknown platform - only use console sink
break;
if (loggingConsent === true) {
// Add platform-specific Datadog sink
switch (platform) {
case "browser": {
const sink = new BrowserDatadogSink(environment, datadogLogger);
walletsLogger.addSink(sink);
break;
}
case "react-native": {
// React Native logger initialization is handled by @crossmint/client-sdk-react-native-ui
// This package only initializes for browser/server to avoid bundling React Native dependencies
// The React Native UI package will initialize the logger with the appropriate Datadog sink
break;
}
case "server": {
const sink = new ServerDatadogSink(environment);
walletsLogger.addSink(sink);
break;
}
default: {
// Unknown platform - only use console sink
break;
}
}
}
}
2 changes: 1 addition & 1 deletion packages/wallets/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class CrossmintWallets {
private readonly walletFactory: WalletFactory;

private constructor(crossmint: Crossmint) {
initWalletsLogger(crossmint.apiKey);
initWalletsLogger(crossmint.apiKey, crossmint.loggingConsent);
const apiClient = new ApiClient(crossmint);
this.walletFactory = new WalletFactory(apiClient);

Expand Down