@picked/telemetry 0.0.101-next.2 → 0.0.101-next.3

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/README.md CHANGED
@@ -1,38 +1,46 @@
1
1
  # @picked/telemetry
2
2
 
3
- A minimal OTLP/HTTP-JSON span emitter shared by the Picked SDK surfaces.
3
+ The OpenTelemetry span emitter the Picked CLI and SDK use to report their own performance. An
4
+ application does not need it.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @picked/telemetry
10
+ ```
4
11
 
5
12
  ## Usage
6
13
 
7
14
  ```typescript
8
15
  import { createSpanId, createTelemetryEmitter, createTraceId, toUnixNano } from '@picked/telemetry'
9
16
 
17
+ const startedAt = Date.now()
10
18
  const emitter = createTelemetryEmitter({
11
- endpoint: 'https://production.otel.picked.app/v1/traces',
12
- resource: { 'service.name': 'picked-sdk' },
13
- headers: { 'Picked-Telemetry': 'cli' },
19
+ endpoint: 'https://otel.example.com/v1/traces',
20
+ resource: { 'service.name': 'my-tool' },
14
21
  })
15
22
 
16
23
  emitter.record({
17
- name: 'picked.start',
24
+ name: 'my-tool.run',
18
25
  traceId: createTraceId(),
19
26
  spanId: createSpanId(),
20
27
  startTimeUnixNano: toUnixNano(startedAt),
21
- endTimeUnixNano: toUnixNano(finishedAt),
22
- attributes: { 'picked.data.mode': 'api' },
28
+ endTimeUnixNano: toUnixNano(Date.now()),
29
+ attributes: {},
23
30
  status: 'ok',
24
31
  })
25
32
 
26
33
  await emitter.flush()
27
34
  ```
28
35
 
29
- ## Constraints
36
+ It sends OTLP/HTTP JSON with `fetch`, has no dependencies, and never throws: a failed batch is
37
+ dropped.
38
+
39
+ ## Docs
40
+
41
+ This package has no page of its own; it serves the Picked SDK and CLI.
30
42
 
31
- - **No runtime dependencies, and none from `@opentelemetry/*`.** Enforced by
32
- `src/package-safety.test.ts`.
33
- - **No Node built-ins.** The same test pins it, so the package bundles into a browser page.
34
- - **Nothing it does can surface to the host.** A blocked request, an offline machine, a
35
- refused batch and a runtime without `fetch` all resolve quietly. A failed batch is
36
- dropped rather than retried, which is what bounds the buffer on a long-lived page.
37
- - **`fetch` with `keepalive`, never `sendBeacon`.** `sendBeacon` cannot set request headers,
38
- and the ingest-channel marker has to travel on the request.
43
+ - **Web:** [Picked SDK](https://docs.picked.app/reference/sdk)
44
+ - **Local:** `node_modules/picked/docs/reference/sdk/index.md`. The `picked` package carries every page under `node_modules/picked/docs/`.
45
+ - **CLI:** `npx picked docs read /reference/sdk`. `npx picked docs list [words]` lists the pages.
46
+ - **MCP:** call `read_picked_doc` with `{ "path": "/reference/sdk" }`; `list_picked_docs` lists the pages. Add the server with `claude mcp add --transport http picked https://api.picked.app/mcp`, or see [How to connect the MCP server](https://docs.picked.app/how-to/connect-the-mcp-server) for other tools.
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`@picked/telemetry`,t={unset:0,ok:1,error:2};function n(){return`0.0.101-next.2`}function r(e){return typeof e==`string`?{stringValue:e}:typeof e==`boolean`?{boolValue:e}:Number.isInteger(e)?{intValue:e.toString()}:{doubleValue:e}}function i(e){return Object.entries(e).map(([e,t])=>({key:e,value:r(t)}))}function a(e){return{traceId:e.traceId,spanId:e.spanId,...e.parentSpanId?{parentSpanId:e.parentSpanId}:{},name:e.name,kind:1,startTimeUnixNano:e.startTimeUnixNano,endTimeUnixNano:e.endTimeUnixNano,attributes:i(e.attributes),status:{code:t[e.status]}}}function o(t,r){return{resourceSpans:[{resource:{attributes:i(t)},scopeSpans:[{scope:{name:e,version:n()},spans:r.map(a)}]}]}}var s=`https://production.otel.picked.app/v1/traces`,c=50,l=3e3;function u(e){let t=e.endpoint??`https://production.otel.picked.app/v1/traces`,n=e.maxBatchSize??c,r=[];async function i(){if(r.length===0)return;let n=r;r=[];let i=globalThis.fetch;if(typeof i==`function`)try{await i(t,{method:`POST`,keepalive:!0,headers:{"Content-Type":`application/json`,...e.headers},body:JSON.stringify(o(e.resource,n)),signal:AbortSignal.timeout(l)})}catch{}}return{record:e=>{r.push(e),r.length>=n&&i()},flush:i,bufferedCount:()=>r.length}}var d=16,f=8;function p(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),t.every(e=>e===0)&&(t[0]=1),t}function m(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}function h(){return m(p(d))}function g(){return m(p(f))}function _(e,t,n){return`00-${e}-${t}-${n?`01`:`00`}`}var v=1000000n;function y(e){let t=Math.trunc(e),n=Math.round((e-t)*Number(v));return(BigInt(t)*v+BigInt(n)).toString()}exports.DEFAULT_TELEMETRY_ENDPOINT=s,exports.createSpanId=g,exports.createTelemetryEmitter=u,exports.createTraceId=h,exports.formatTraceparent=_,exports.toUnixNano=y;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`@picked/telemetry`,t={unset:0,ok:1,error:2};function n(){return`0.0.101-next.3`}function r(e){return typeof e==`string`?{stringValue:e}:typeof e==`boolean`?{boolValue:e}:Number.isInteger(e)?{intValue:e.toString()}:{doubleValue:e}}function i(e){return Object.entries(e).map(([e,t])=>({key:e,value:r(t)}))}function a(e){return{traceId:e.traceId,spanId:e.spanId,...e.parentSpanId?{parentSpanId:e.parentSpanId}:{},name:e.name,kind:1,startTimeUnixNano:e.startTimeUnixNano,endTimeUnixNano:e.endTimeUnixNano,attributes:i(e.attributes),status:{code:t[e.status]}}}function o(t,r){return{resourceSpans:[{resource:{attributes:i(t)},scopeSpans:[{scope:{name:e,version:n()},spans:r.map(a)}]}]}}var s=`https://production.otel.picked.app/v1/traces`,c=50,l=3e3;function u(e){let t=e.endpoint??`https://production.otel.picked.app/v1/traces`,n=e.maxBatchSize??c,r=[];async function i(){if(r.length===0)return;let n=r;r=[];let i=globalThis.fetch;if(typeof i==`function`)try{await i(t,{method:`POST`,keepalive:!0,headers:{"Content-Type":`application/json`,...e.headers},body:JSON.stringify(o(e.resource,n)),signal:AbortSignal.timeout(l)})}catch{}}return{record:e=>{r.push(e),r.length>=n&&i()},flush:i,bufferedCount:()=>r.length}}var d=16,f=8;function p(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),t.every(e=>e===0)&&(t[0]=1),t}function m(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}function h(){return m(p(d))}function g(){return m(p(f))}function _(e,t,n){return`00-${e}-${t}-${n?`01`:`00`}`}var v=1000000n;function y(e){let t=Math.trunc(e),n=Math.round((e-t)*Number(v));return(BigInt(t)*v+BigInt(n)).toString()}exports.DEFAULT_TELEMETRY_ENDPOINT=s,exports.createSpanId=g,exports.createTelemetryEmitter=u,exports.createTraceId=h,exports.formatTraceparent=_,exports.toUnixNano=y;
package/dist/esm/index.js CHANGED
@@ -5,7 +5,7 @@ var e = {
5
5
  error: 2
6
6
  };
7
7
  function t() {
8
- return "0.0.101-next.2";
8
+ return "0.0.101-next.3";
9
9
  }
10
10
  function n(e) {
11
11
  return typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : Number.isInteger(e) ? { intValue: e.toString() } : { doubleValue: e };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@picked/telemetry",
3
3
  "description": "Minimal OTLP/HTTP-JSON span emitter shared by the Picked SDK surfaces",
4
- "version": "0.0.101-next.2",
4
+ "version": "0.0.101-next.3",
5
5
  "dependencies": {},
6
6
  "devDependencies": {
7
7
  "@repo/eslint-config": "workspace:*",