This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add client tracing to on-chain & intra-ledger payments
- Loading branch information
Theophilus Isah
authored and
Theophilus Isah
committed
Sep 26, 2022
1 parent
5d86b21
commit 38ff2d4
Showing
8 changed files
with
407 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { trace } from "@opentelemetry/api" | ||
import { ZoneContextManager } from "@opentelemetry/context-zone" | ||
import { registerInstrumentations } from "@opentelemetry/instrumentation" | ||
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch" | ||
import { BatchSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/tracing" | ||
import { WebTracerProvider } from "@opentelemetry/web" | ||
|
||
const provider = new WebTracerProvider({}) | ||
|
||
provider.addSpanProcessor(new BatchSpanProcessor(new ConsoleSpanExporter())) | ||
|
||
trace.setGlobalTracerProvider(provider) | ||
const name = "galoy-web-wallet" | ||
const version = "0.1.0" | ||
export const tracer = trace.getTracer(name, version) | ||
|
||
const fetchInstrumentation = new FetchInstrumentation() | ||
fetchInstrumentation.setTracerProvider(provider) | ||
|
||
provider.register({ | ||
contextManager: new ZoneContextManager(), | ||
}) | ||
|
||
registerInstrumentations({ | ||
instrumentations: [fetchInstrumentation], | ||
}) | ||
|
||
export type TraceProviderProps = { | ||
children?: React.ReactNode | ||
} | ||
|
||
export default function TraceProvider({ children }: TraceProviderProps) { | ||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { trace, context, Span } from "@opentelemetry/api" | ||
|
||
export const reportSpan = (span: Span) => { | ||
console.log("report span:", span) | ||
|
||
fetch("./send-trace", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(span), | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => console.log(data)) | ||
.catch((error) => { | ||
console.error("Error:", error) | ||
}) | ||
} | ||
|
||
export const withTracing = async (name: string, parentSpan: Span, cb?: () => void) => { | ||
const tracer = trace.getTracer("galoy-web-wallet") | ||
let span = trace.getSpan(context.active()) | ||
|
||
if (parentSpan) { | ||
const ctx = trace.setSpan(context.active(), parentSpan) | ||
span = tracer.startSpan(name, undefined, ctx) | ||
} else { | ||
span = tracer.startSpan(name) | ||
} | ||
|
||
if (cb) { | ||
await cb() | ||
} | ||
|
||
span.end() | ||
|
||
reportSpan(span) | ||
} | ||
|
||
export const getTracer = () => { | ||
return trace.getTracer("galoy-web-wallet") | ||
} |
Oops, something went wrong.