The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import Constants from "expo-constants"; |
| 2 | import { type ReleaseChannel, releaseResourceAttributes } from "@t3tools/shared/releaseResource"; |
| 3 | import * as RelayTracing from "@t3tools/shared/relayTracing"; |
| 4 | |
| 5 | import { hasTracingPublicConfig, resolveCloudPublicConfig } from "../cloud/publicConfig"; |
| 6 | |
| 7 | export interface TracingConfig { |
| 8 | readonly tracesUrl: string; |
| 9 | readonly tracesDataset: string; |
| 10 | readonly tracesToken: string; |
| 11 | } |
| 12 | |
| 13 | export interface TracingResource { |
| 14 | readonly serviceVersion?: string; |
| 15 | readonly serviceInstanceId: string; |
| 16 | readonly appVariant: string; |
| 17 | } |
| 18 | |
| 19 | const RELEASE_CHANNEL_BY_VARIANT: Readonly<Record<string, ReleaseChannel | undefined>> = { |
| 20 | development: "dev", |
| 21 | preview: "preview", |
| 22 | production: "stable", |
| 23 | }; |
| 24 | |
| 25 | export function resolveTracingConfig(): TracingConfig | null { |
| 26 | const config = resolveCloudPublicConfig(); |
| 27 | if (!hasTracingPublicConfig(config)) { |
| 28 | return null; |
| 29 | } |
| 30 | const { tracesUrl, tracesDataset, tracesToken } = config.observability; |
| 31 | return { tracesUrl, tracesDataset, tracesToken }; |
| 32 | } |
| 33 | |
| 34 | export function layerFromConfig(config: TracingConfig | null, resource: TracingResource) { |
| 35 | const channel = |
| 36 | typeof __DEV__ !== "undefined" && __DEV__ |
| 37 | ? "dev" |
| 38 | : RELEASE_CHANNEL_BY_VARIANT[resource.appVariant]; |
| 39 | return RelayTracing.layer(config, { |
| 40 | serviceName: "t3code-mobile", |
| 41 | serviceVersion: resource.serviceVersion, |
| 42 | runtime: "react-native", |
| 43 | serviceInstanceId: resource.serviceInstanceId, |
| 44 | client: `mobile-${resource.appVariant}`, |
| 45 | attributes: channel && releaseResourceAttributes(channel), |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | export const layer = layerFromConfig(resolveTracingConfig(), { |
| 50 | serviceVersion: Constants.expoConfig?.version, |
| 51 | serviceInstanceId: Constants.sessionId, |
| 52 | appVariant: |
| 53 | typeof Constants.expoConfig?.extra?.appVariant === "string" |
| 54 | ? Constants.expoConfig.extra.appVariant |
| 55 | : "unknown", |
| 56 | }); |