@thesight/sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,114 @@
1
- import { Connection, type ConnectionConfig, type Transaction, type VersionedTransaction, type SendOptions, type Commitment } from '@solana/web3.js';
2
- import { type Tracer } from '@opentelemetry/api';
3
- import type { AnchorIdl, DecodedError, CpiTree } from '@thesight/core';
4
- export interface SightConfig {
1
+ import { Connection, ConnectionConfig, Commitment, Transaction, VersionedTransaction, SendOptions } from '@solana/web3.js';
2
+ import { Tracer } from '@opentelemetry/api';
3
+ import { AnchorIdl, CpiTree, DecodedError } from '@thesight/core';
4
+ export { AnchorIdl, CpiTree, CuAttribution, DecodedError, FlamegraphItem, IdlResolver } from '@thesight/core';
5
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
6
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
7
+ import { ExportResult } from '@opentelemetry/core';
8
+
9
+ interface InitSightConfig {
10
+ /** Project API key (`sk_live_...`) from the Sight dashboard. */
11
+ apiKey: string;
12
+ /**
13
+ * Human-readable service name that shows up on every span. Pick something
14
+ * that identifies this process — `'swap-bot'`, `'market-maker'`,
15
+ * `'trade-settler'`, etc.
16
+ */
17
+ serviceName: string;
18
+ /** Optional version string for the service. Useful for correlating spans with a deploy. */
19
+ serviceVersion?: string;
20
+ /**
21
+ * Full ingest URL. Defaults to the hosted Sight ingest. Override for
22
+ * local development (e.g. `http://localhost:3001/ingest`) or self-hosted
23
+ * deployments.
24
+ */
25
+ ingestUrl?: string;
26
+ /** BatchSpanProcessor flush interval, in ms. Defaults to 5s. */
27
+ batchDelayMs?: number;
28
+ /** Max spans per HTTP POST. Clamped to 100 by the exporter. */
29
+ maxBatchSize?: number;
30
+ /** Inject a fetch implementation for tests. Defaults to global fetch. */
31
+ fetchImpl?: typeof fetch;
32
+ }
33
+ interface SightTracerHandle {
34
+ provider: NodeTracerProvider;
35
+ /** Flush any pending spans and release the batch processor. */
36
+ shutdown: () => Promise<void>;
37
+ }
38
+ /**
39
+ * Initialize Sight tracing. Call this **once** near the top of your
40
+ * process entry point — typically in the same file that boots your
41
+ * HTTP server or worker.
42
+ *
43
+ * import { initSight, InstrumentedConnection } from '@thesight/sdk';
44
+ *
45
+ * initSight({
46
+ * apiKey: process.env.SIGHT_API_KEY!,
47
+ * serviceName: 'swap-bot',
48
+ * ingestUrl: process.env.SIGHT_INGEST_URL, // optional, defaults to prod
49
+ * });
50
+ *
51
+ * const connection = new InstrumentedConnection(process.env.RPC_URL!);
52
+ * const { signature } = await connection.sendAndConfirmInstrumented(tx);
53
+ *
54
+ * Registers a NodeTracerProvider as the global OTel tracer, so any call to
55
+ * `trace.getTracer(...)` (including the ones inside `InstrumentedConnection`)
56
+ * routes spans through the Sight exporter. Context propagation uses the
57
+ * Node async hooks manager so spans nest correctly across await boundaries.
58
+ *
59
+ * Returns a handle with a `shutdown()` method. Call it at graceful shutdown
60
+ * time so pending spans are flushed before the process exits:
61
+ *
62
+ * const sight = initSight({ ... });
63
+ * process.on('SIGTERM', async () => {
64
+ * await sight.shutdown();
65
+ * process.exit(0);
66
+ * });
67
+ */
68
+ declare function initSight(config: InitSightConfig): SightTracerHandle;
69
+
70
+ interface SightExporterConfig {
71
+ /** Project API key (`sk_live_...`). Sent as Bearer auth on every POST. */
72
+ apiKey: string;
73
+ /**
74
+ * Full ingest URL including the path (e.g. `https://ingest.thesight.dev/ingest`
75
+ * or `http://localhost:3001/ingest` for local dev).
76
+ */
77
+ ingestUrl: string;
78
+ /** Inject a fake fetch in tests. Defaults to `globalThis.fetch`. */
79
+ fetchImpl?: typeof fetch;
80
+ /** Max spans per POST. Ingest enforces an upper bound of 100. */
81
+ maxBatchSize?: number;
82
+ }
83
+ /**
84
+ * An OTel `SpanExporter` that translates OTel spans to Sight's custom
85
+ * ingest payload shape and POSTs them to `/ingest`.
86
+ *
87
+ * Each span becomes one object in the `spans` array. Solana-specific
88
+ * attributes flow through as-is (the set that `InstrumentedConnection`
89
+ * already populates — `solana.tx.signature`, `solana.tx.cu_used`,
90
+ * `solana.tx.program`, etc). The exporter intentionally does not attempt
91
+ * to translate span events or links — the ingest schema doesn't have
92
+ * slots for those, and we prefer dropping silently over guessing.
93
+ *
94
+ * The BatchSpanProcessor upstream handles retries, timeouts, and batching;
95
+ * this exporter stays a thin wire-format translator.
96
+ */
97
+ declare class SightSpanExporter implements SpanExporter {
98
+ private readonly apiKey;
99
+ private readonly ingestUrl;
100
+ private readonly fetchImpl;
101
+ private readonly maxBatchSize;
102
+ private shuttingDown;
103
+ constructor(config: SightExporterConfig);
104
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): Promise<void>;
105
+ shutdown(): Promise<void>;
106
+ forceFlush(): Promise<void>;
107
+ private sendChunk;
108
+ private convertSpan;
109
+ }
110
+
111
+ interface SightConfig {
5
112
  /** OTel tracer. Get via trace.getTracer('your-service') */
6
113
  tracer?: Tracer;
7
114
  /** Override RPC endpoint for IDL fetching (defaults to same as connection) */
@@ -24,7 +131,7 @@ export interface SightConfig {
24
131
  */
25
132
  allowOnChainIdlFetch?: boolean;
26
133
  }
27
- export interface SightSpanAttributes {
134
+ interface SightSpanAttributes {
28
135
  'solana.tx.signature': string;
29
136
  'solana.tx.status': 'confirmed' | 'failed' | 'timeout';
30
137
  'solana.tx.slot'?: number;
@@ -55,7 +162,7 @@ export interface SightSpanAttributes {
55
162
  * is active when sendAndConfirmTransaction is called — so it automatically
56
163
  * nests inside your HTTP handler or background job span.
57
164
  */
58
- export declare class InstrumentedConnection extends Connection {
165
+ declare class InstrumentedConnection extends Connection {
59
166
  private sightConfig;
60
167
  private idlResolver;
61
168
  private tracer;
@@ -83,10 +190,5 @@ export declare class InstrumentedConnection extends Connection {
83
190
  error?: DecodedError;
84
191
  }>;
85
192
  }
86
- export { IdlResolver } from '@thesight/core';
87
- export type { CpiTree, CuAttribution, FlamegraphItem, DecodedError, AnchorIdl } from '@thesight/core';
88
- export { initSight } from './init.js';
89
- export type { InitSightConfig, SightTracerHandle } from './init.js';
90
- export { SightSpanExporter } from './exporter.js';
91
- export type { SightExporterConfig } from './exporter.js';
92
- //# sourceMappingURL=index.d.ts.map
193
+
194
+ export { type InitSightConfig, InstrumentedConnection, type SightConfig, type SightExporterConfig, type SightSpanAttributes, SightSpanExporter, type SightTracerHandle, initSight };