Skip to content
Merged
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
14 changes: 9 additions & 5 deletions app2/app2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ _: {
pnpm_10
imagemagick
];
PUBLIC_DATADOG_CLIENT_TOKEN = "pub69b8a3deb766e91a19b44cccf0c3352e";
PUBLIC_LOG_TOKEN = "9VE47r89qMgdbCzHbtRN8pTuQyU9cWVsZMnAwyGU";
PUBLIC_LOG_ENDPOINT = "https://logs.union.build/app";
PUBLIC_GIT_REV = gitShortRev;
PUBLIC_LAST_MODIFIED_DATE = lastModifiedDate;
PUBLIC_LAST_MODIFIED_EPOCH = lastModified;
Expand All @@ -38,7 +39,7 @@ _: {
../ts-sdk-evm
../ts-sdk-sui
];
hash = "sha256-IyY4ALBfwVBGibjJFhLGtIN2OutgaRlndpmA+MzbF1g=";
hash = "sha256-ihwIWIgmF9XrEDf9rINtpR9OWLJmS4HtxYFsShY9e3g=";
buildInputs = deps;
nativeBuildInputs = buildInputs;
pnpmWorkspaces = [
Expand All @@ -51,7 +52,8 @@ _: {
];
buildPhase = ''
runHook preBuild
export PUBLIC_DATADOG_CLIENT_TOKEN="${PUBLIC_DATADOG_CLIENT_TOKEN}"
export PUBLIC_LOG_TOKEN="${PUBLIC_LOG_TOKEN}"
export PUBLIC_LOG_ENDPOINT="${PUBLIC_LOG_ENDPOINT}"
export PUBLIC_GIT_REV="${PUBLIC_GIT_REV}"
export PUBLIC_LAST_MODIFIED_DATE="${PUBLIC_LAST_MODIFIED_DATE}"
export PUBLIC_LAST_MODIFIED_EPOCH="${PUBLIC_LAST_MODIFIED_EPOCH}"
Expand Down Expand Up @@ -82,7 +84,8 @@ _: {
text = ''
${ensureAtRepositoryRoot}
cd app2/
export PUBLIC_DATADOG_CLIENT_TOKEN="${PUBLIC_DATADOG_CLIENT_TOKEN}"
export PUBLIC_LOG_TOKEN="${PUBLIC_LOG_TOKEN}"
export PUBLIC_LOG_ENDPOINT="${PUBLIC_LOG_ENDPOINT}"
export PUBLIC_GIT_REV="${PUBLIC_GIT_REV}"
export PUBLIC_LAST_MODIFIED_DATE="${PUBLIC_LAST_MODIFIED_DATE}"
export PUBLIC_LAST_MODIFIED_EPOCH="${PUBLIC_LAST_MODIFIED_EPOCH}"
Expand All @@ -102,7 +105,8 @@ _: {
text = ''
${ensureAtRepositoryRoot}
cd app2/
export PUBLIC_DATADOG_CLIENT_TOKEN="${PUBLIC_DATADOG_CLIENT_TOKEN}"
export PUBLIC_LOG_TOKEN="${PUBLIC_LOG_TOKEN}"
export PUBLIC_LOG_ENDPOINT="${PUBLIC_LOG_ENDPOINT}"
export PUBLIC_GIT_REV="${PUBLIC_GIT_REV}"
export PUBLIC_LAST_MODIFIED_DATE="${PUBLIC_LAST_MODIFIED_DATE}"
export PUBLIC_LAST_MODIFIED_EPOCH="${PUBLIC_LAST_MODIFIED_EPOCH}"
Expand Down
13 changes: 11 additions & 2 deletions app2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@cosmjs/proto-signing": "catalog:",
"@cosmjs/stargate": "catalog:",
"@cosmjs/tendermint-rpc": "catalog:",
"@datadog/browser-logs": "^6.6.4",
"@effect/experimental": "catalog:",
"@effect/opentelemetry": "catalog:",
"@effect/platform": "catalog:",
"@effect/typeclass": "catalog:",
"@effect/vitest": "catalog:",
Expand All @@ -36,6 +36,15 @@
"@mysten/sui": "^1.38.0",
"@mysten/wallet-standard": "^0.19.3",
"@number-flow/svelte": "^0.3.7",
"@opentelemetry/exporter-logs-otlp-proto": "catalog:",
"@opentelemetry/exporter-metrics-otlp-http": "catalog:",
"@opentelemetry/exporter-metrics-otlp-proto": "catalog:",
"@opentelemetry/exporter-trace-otlp-http": "catalog:",
"@opentelemetry/exporter-trace-otlp-proto": "catalog:",
"@opentelemetry/sdk-logs": "catalog:",
"@opentelemetry/sdk-metrics": "catalog:",
"@opentelemetry/sdk-trace-base": "catalog:",
"@opentelemetry/sdk-trace-web": "catalog:",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@safe-global/safe-gateway-typescript-sdk": "^3.23.1",
"@scure/base": "^1.2.4",
Expand All @@ -52,9 +61,9 @@
"@unionlabs/sdk-cosmos": "workspace:*",
"@unionlabs/sdk-evm": "workspace:*",
"@unionlabs/sdk-sui": "workspace:*",
"bs58": "^6",
"@wagmi/connectors": "^5.7.12",
"@wagmi/core": "^2.16.7",
"bs58": "^6",
"clsx": "^2.1.1",
"effect": "catalog:",
"eslint": "^9.24.0",
Expand Down
1 change: 0 additions & 1 deletion app2/src/hooks.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const cleanupStorage = () => {

export const init: ClientInit = async () => {
await import("$lib/runtime").then(x => x.__init())
await import("$lib/logging/datadog").then(x => x.__init())

try {
cleanupStorage()
Expand Down
7 changes: 4 additions & 3 deletions app2/src/lib/graphql/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ export class GraphQLError extends S.TaggedError<GraphQLError>("GraphQLError")("G
static fromUnknown(error: unknown) {
return pipe(
Match.value(error),
Match.when(Match.instanceOf(ClientError), this.fromClientError),
Match.when(Match.instanceOf(ClientError), (error) => GraphQLError.fromClientError(error)),
Match.orElse((error) =>
this.make({
GraphQLError.make({
cause: error,
message: String(error) ?? "Unknown error",
status: -1,
})
),
)
}

static fromClientError(error: ClientError) {
return this.make({
return GraphQLError.make({
message: error.message,
status: error.response.status,
errors: error.response.errors,
Expand Down
16 changes: 7 additions & 9 deletions app2/src/lib/layers/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ENV } from "$lib/constants"
import { SupabaseClient } from "$lib/dashboard/client"
import { GasPriceMap } from "$lib/gasprice"
import { GraphQL } from "$lib/graphql/service"
import * as Datadog from "$lib/logging/datadog"
import * as Tracing from "$lib/logging/tracing"
import * as SvelteConfigProvider from "$lib/services/SvelteConfigProvider.js"
import { PriceOracle } from "@unionlabs/sdk"
import { Indexer } from "@unionlabs/sdk/Indexer"
Expand All @@ -28,16 +28,14 @@ export default Layer.mergeAll(
PriceOracle.layerExecutor,
SupabaseClient.Default({ auth: { autoRefreshToken: true } }),
IndexerLive,
Tracing.TracingLive,
Logger.replace(
Logger.defaultLogger,
Logger.zip(
Logger.prettyLogger({
colors: true,
mode: "browser",
stderr: true,
}),
Datadog.Logger,
),
Logger.prettyLogger({
colors: true,
mode: "browser",
stderr: true,
}),
),
minimumLogLevel,
)
82 changes: 0 additions & 82 deletions app2/src/lib/logging/datadog.ts

This file was deleted.

92 changes: 92 additions & 0 deletions app2/src/lib/logging/tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { PUBLIC_GIT_REV, PUBLIC_LOG_ENDPOINT, PUBLIC_LOG_TOKEN } from "$env/static/public"
import { ENV } from "$lib/constants.js"
import * as WebSdk from "@effect/opentelemetry/WebSdk"
import { OTLPLogExporter as ProtoOTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto"
import { OTLPMetricExporter as HttpOTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http"
import { OTLPMetricExporter as ProtoOTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto"
import { OTLPTraceExporter as HttpOTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
import { OTLPTraceExporter as ProtoOTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"
import {
BatchLogRecordProcessor,
ConsoleLogRecordExporter,
SimpleLogRecordProcessor,
} from "@opentelemetry/sdk-logs"
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics"
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"
import { Effect, Layer, Match, Option, pipe, String as Str } from "effect"

export const TracingLive = Layer.unwrapEffect(
Effect.gen(function*() {
const serviceName = "app"
const serviceVersion = PUBLIC_GIT_REV

const env = pipe(
Match.value(ENV()),
Match.when("PRODUCTION", () => "production" as const),
Match.when("STAGING", () => "staging" as const),
Match.when("DEVELOPMENT", () => "development" as const),
Match.exhaustive,
)

if (env === "development") {
return WebSdk.layer(() => ({
resource: {
serviceName,
serviceVersion,
attributes: {
env,
},
},
logRecordProcessor: new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()),
spanProcessor: new BatchSpanProcessor(new HttpOTLPTraceExporter()),
metricReader: new PeriodicExportingMetricReader({
exporter: new HttpOTLPMetricExporter({}),
}),
}))
}

const endpoint = pipe(
Option.fromNullable(PUBLIC_LOG_ENDPOINT),
Option.flatMap(Option.liftPredicate(Str.isNonEmpty)),
)

if (Option.isNone(endpoint) || Str.isEmpty(endpoint.value)) {
yield* Effect.logWarning(
`The app is running in a ${env} environment, but no OTEL logging endpoint is configured.`,
)
return Layer.empty
}

const headers = {
Authorization: `Bearer ${PUBLIC_LOG_TOKEN}`,
}

return WebSdk.layer(() => ({
resource: {
serviceName,
serviceVersion,
attributes: {
env,
},
},
logRecordProcessor: new BatchLogRecordProcessor(
new ProtoOTLPLogExporter({
url: `${endpoint.value}/v1/logs`,
headers,
}),
),
spanProcessor: new BatchSpanProcessor(
new ProtoOTLPTraceExporter({
url: `${endpoint.value}/v1/traces`,
headers,
}),
),
metricReader: new PeriodicExportingMetricReader({
exporter: new ProtoOTLPMetricExporter({
url: `${endpoint.value}/v1/metrics`,
headers,
}),
}),
}))
}),
)
2 changes: 1 addition & 1 deletion ceremony/ceremony.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _: {
{
packages = {
ceremony = buildPnpmPackage {
hash = "sha256-1R/7+vIllXY+KmNgxxH2fEHM4UzVmHDiDA3XqmODuJI=";
hash = "sha256-wXt2qKEtXRSgb63jsoNAtu71dUtD2fAuRmcMM3wnobw=";
packageJsonPath = ./package.json;
extraSrcs = pkgs.lib.fileset.unions [
../ceremony
Expand Down
2 changes: 1 addition & 1 deletion effect-svelte/effect-svelte.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _: {
packageJsonPath = ./package.json;
extraSrcs = pkgs.lib.fileset.unions [ ./. ];
pnpmWorkspaces = [ "@unionlabs/effect-svelte" ];
hash = "sha256-q+7B/VoFaV85Mt2hQWJBFIEQH5zVdwoESqgqhMxKCJU=";
hash = "sha256-CXZ+Vc7IkmrZkvKTyNiDCGQUKH2HJhGaHgHVZ69zv0E=";
doCheck = true;
buildPhase = ''
runHook preBuild
Expand Down
Loading