@miradorlabs/parallax-web 1.0.0 → 1.0.2

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
@@ -13,7 +13,7 @@ npm install @miradorlabs/parallax-web
13
13
  ### Basic Setup
14
14
 
15
15
  ```typescript
16
- import { ParallaxClient } from '@miradorlabs/parallax-web';
16
+ import { ParallaxClient, CreateTraceRequest } from '@miradorlabs/parallax-web';
17
17
 
18
18
  // Initialize the client with your API key
19
19
  const client = new ParallaxClient('your-api-key');
@@ -25,133 +25,160 @@ const client = new ParallaxClient('your-api-key', 'https://your-gateway.example.
25
25
  ### Creating a Trace
26
26
 
27
27
  ```typescript
28
- const traceResponse = await client.createTrace({
29
- name: 'My Application Trace',
30
- attributes: {
31
- 'project.id': 'my-project',
32
- 'environment': 'production',
33
- },
34
- tags: ['web', 'user-action'],
35
- });
36
-
37
- const traceId = traceResponse.traceId;
28
+ import { CreateTraceRequest } from '@miradorlabs/parallax-web';
29
+
30
+ const request = new CreateTraceRequest();
31
+ request.setName('My Application Trace');
32
+
33
+ // Set attributes using the map
34
+ const attributesMap = request.getAttributesMap();
35
+ attributesMap.set('project.id', 'my-project');
36
+ attributesMap.set('environment', 'production');
37
+
38
+ request.setTagsList(['web', 'user-action']);
39
+
40
+ const traceResponse = await client.createTrace(request);
41
+ const traceId = traceResponse.getTraceId();
38
42
  ```
39
43
 
40
44
  ### Starting a Span
41
45
 
42
46
  ```typescript
43
- const spanResponse = await client.startSpan({
44
- name: 'User Login',
45
- traceId: traceId,
46
- attributes: {
47
- 'user.id': 'user-123',
48
- 'action': 'login',
49
- },
50
- });
51
-
52
- const spanId = spanResponse.spanId;
53
- ```
47
+ import { StartSpanRequest } from '@miradorlabs/parallax-web';
54
48
 
55
- ### Adding Span Attributes
49
+ const request = new StartSpanRequest();
50
+ request.setName('User Login');
51
+ request.setTraceId(traceId);
56
52
 
57
- ```typescript
58
- await client.addSpanAttributes({
59
- traceId: traceId,
60
- spanId: spanId,
61
- attributes: {
62
- 'response.status': '200',
63
- 'response.time': '145ms',
64
- },
65
- });
53
+ // Set attributes using the map
54
+ const attributesMap = request.getAttributesMap();
55
+ attributesMap.set('user.id', 'user-123');
56
+ attributesMap.set('action', 'login');
57
+
58
+ const spanResponse = await client.startSpan(request);
59
+ const spanId = spanResponse.getSpanId();
66
60
  ```
67
61
 
68
62
  ### Adding Span Events
69
63
 
70
64
  ```typescript
71
- await client.addSpanEvent({
72
- traceId: traceId,
73
- spanId: spanId,
74
- eventName: 'User Authenticated',
75
- attributes: {
76
- 'auth.method': 'oauth',
77
- 'auth.provider': 'google',
78
- },
79
- });
65
+ import { AddSpanEventRequest } from '@miradorlabs/parallax-web';
66
+
67
+ const request = new AddSpanEventRequest();
68
+ request.setTraceId(traceId);
69
+ request.setSpanId(spanId);
70
+ request.setEventName('User Authenticated');
71
+
72
+ const attributesMap = request.getAttributesMap();
73
+ attributesMap.set('auth.method', 'oauth');
74
+ attributesMap.set('auth.provider', 'google');
75
+
76
+ await client.addSpanEvent(request);
80
77
  ```
81
78
 
82
79
  ### Adding Span Errors
83
80
 
84
81
  ```typescript
85
- await client.addSpanError({
86
- traceId: traceId,
87
- spanId: spanId,
88
- errorType: 'ValidationError',
89
- message: 'Invalid email format',
90
- stackTrace: error.stack,
91
- attributes: {
92
- 'error.field': 'email',
93
- },
94
- });
82
+ import { AddSpanErrorRequest } from '@miradorlabs/parallax-web';
83
+
84
+ const request = new AddSpanErrorRequest();
85
+ request.setTraceId(traceId);
86
+ request.setSpanId(spanId);
87
+ request.setErrorType('ValidationError');
88
+ request.setMessage('Invalid email format');
89
+ request.setStackTrace(error.stack);
90
+
91
+ const attributesMap = request.getAttributesMap();
92
+ attributesMap.set('error.field', 'email');
93
+
94
+ await client.addSpanError(request);
95
95
  ```
96
96
 
97
97
  ### Adding Span Hints (Blockchain Transactions)
98
98
 
99
99
  ```typescript
100
- await client.addSpanHint({
101
- traceId: traceId,
102
- parentSpanId: spanId,
103
- chainTransaction: {
104
- txHash: '0x1234567890abcdef',
105
- chainId: 1, // Ethereum mainnet
106
- },
107
- });
100
+ import { AddSpanHintRequest } from '@miradorlabs/parallax-web';
101
+
102
+ const chainTx = new AddSpanHintRequest.ChainTransaction();
103
+ chainTx.setTxHash('0x1234567890abcdef');
104
+ chainTx.setChainId(1); // Ethereum mainnet
105
+
106
+ const request = new AddSpanHintRequest();
107
+ request.setTraceId(traceId);
108
+ request.setParentSpanId(spanId);
109
+ request.setChainTransaction(chainTx);
110
+
111
+ await client.addSpanHint(request);
108
112
  ```
109
113
 
110
114
  ### Finishing a Span
111
115
 
112
116
  ```typescript
113
- await client.finishSpan({
114
- traceId: traceId,
115
- spanId: spanId,
116
- });
117
+ import { FinishSpanRequest } from '@miradorlabs/parallax-web';
118
+
119
+ const spanStatus = new FinishSpanRequest.SpanStatus();
120
+ spanStatus.setCode(FinishSpanRequest.SpanStatus.StatusCode.STATUS_CODE_OK);
121
+
122
+ const request = new FinishSpanRequest();
123
+ request.setTraceId(traceId);
124
+ request.setSpanId(spanId);
125
+ request.setStatus(spanStatus);
126
+
127
+ await client.finishSpan(request);
117
128
  ```
118
129
 
119
130
  ## Complete Example
120
131
 
121
132
  ```typescript
122
- import { ParallaxClient } from '@miradorlabs/parallax-web';
133
+ import {
134
+ ParallaxClient,
135
+ CreateTraceRequest,
136
+ StartSpanRequest,
137
+ AddSpanEventRequest,
138
+ FinishSpanRequest,
139
+ } from '@miradorlabs/parallax-web';
123
140
 
124
141
  async function trackUserAction() {
125
142
  const client = new ParallaxClient('your-api-key');
126
143
 
127
144
  try {
128
145
  // Create trace
129
- const { traceId } = await client.createTrace({
130
- name: 'User Purchase Flow',
131
- attributes: { 'user.id': 'user-123' },
132
- tags: ['purchase', 'web'],
133
- });
146
+ const createTraceReq = new CreateTraceRequest();
147
+ createTraceReq.setName('User Purchase Flow');
148
+ createTraceReq.getAttributesMap().set('user.id', 'user-123');
149
+ createTraceReq.setTagsList(['purchase', 'web']);
150
+
151
+ const traceResponse = await client.createTrace(createTraceReq);
152
+ const traceId = traceResponse.getTraceId();
134
153
 
135
154
  // Start span
136
- const { spanId } = await client.startSpan({
137
- name: 'Checkout Process',
138
- traceId: traceId,
139
- attributes: { 'cart.items': '3' },
140
- });
155
+ const startSpanReq = new StartSpanRequest();
156
+ startSpanReq.setName('Checkout Process');
157
+ startSpanReq.setTraceId(traceId);
158
+ startSpanReq.getAttributesMap().set('cart.items', '3');
159
+
160
+ const spanResponse = await client.startSpan(startSpanReq);
161
+ const spanId = spanResponse.getSpanId();
141
162
 
142
163
  // Add event
143
- await client.addSpanEvent({
144
- traceId: traceId,
145
- spanId: spanId,
146
- eventName: 'Payment Initiated',
147
- attributes: { 'payment.method': 'card' },
148
- });
164
+ const addEventReq = new AddSpanEventRequest();
165
+ addEventReq.setTraceId(traceId);
166
+ addEventReq.setSpanId(spanId);
167
+ addEventReq.setEventName('Payment Initiated');
168
+ addEventReq.getAttributesMap().set('payment.method', 'card');
169
+
170
+ await client.addSpanEvent(addEventReq);
149
171
 
150
172
  // Finish span
151
- await client.finishSpan({
152
- traceId: traceId,
153
- spanId: spanId,
154
- });
173
+ const finishSpanReq = new FinishSpanRequest();
174
+ finishSpanReq.setTraceId(traceId);
175
+ finishSpanReq.setSpanId(spanId);
176
+
177
+ const spanStatus = new FinishSpanRequest.SpanStatus();
178
+ spanStatus.setCode(FinishSpanRequest.SpanStatus.StatusCode.STATUS_CODE_OK);
179
+ finishSpanReq.setStatus(spanStatus);
180
+
181
+ await client.finishSpan(finishSpanReq);
155
182
  } catch (error) {
156
183
  console.error('Tracing error:', error);
157
184
  }
package/dist/index.d.ts CHANGED
@@ -1,48 +1,43 @@
1
- import * as apiGateway from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway';
2
- import { CreateTraceRequest, StartSpanRequest, FinishSpanRequest, AddSpanAttributesRequest, AddSpanEventRequest, AddSpanErrorRequest, AddSpanHintRequest } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway';
1
+ import { CreateTraceRequest, CreateTraceResponse, StartSpanRequest, StartSpanResponse, FinishSpanRequest, FinishSpanResponse, AddSpanEventRequest, AddSpanEventResponse, AddSpanErrorRequest, AddSpanErrorResponse, AddSpanHintRequest, AddSpanHintResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
2
+ export { AddSpanErrorRequest, AddSpanErrorResponse, AddSpanEventRequest, AddSpanEventResponse, AddSpanHintRequest, AddSpanHintResponse, CreateTraceRequest, CreateTraceResponse, FinishSpanRequest, FinishSpanResponse, StartSpanRequest, StartSpanResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
3
3
  import { Observable } from 'rxjs';
4
4
 
5
5
  declare class ParallaxClient {
6
6
  apiKey?: string | undefined;
7
7
  apiUrl: string;
8
- private apiGatewayRpc;
8
+ private client;
9
9
  constructor(apiKey?: string | undefined, apiUrl?: string);
10
10
  /**
11
11
  * Create a new trace
12
12
  * @param params Parameters to create a new trace
13
13
  * @returns Response from the create trace operation
14
14
  */
15
- createTrace(params: CreateTraceRequest): Promise<apiGateway.CreateTraceResponse>;
15
+ createTrace(params: CreateTraceRequest): Promise<CreateTraceResponse>;
16
16
  /**
17
17
  * Start a new span within a trace
18
18
  * @param params Parameters to start a new span
19
19
  */
20
- startSpan(params: StartSpanRequest): Promise<any>;
20
+ startSpan(params: StartSpanRequest): Promise<StartSpanResponse>;
21
21
  /**
22
22
  * Finish a span within a trace
23
23
  * @param params Parameters to finish a span
24
24
  */
25
- finishSpan(params: FinishSpanRequest): Promise<any>;
26
- /**
27
- * Add attributes to a span
28
- * @param params Parameters to add attributes to a span
29
- */
30
- addSpanAttributes(params: AddSpanAttributesRequest): Promise<any>;
25
+ finishSpan(params: FinishSpanRequest): Promise<FinishSpanResponse>;
31
26
  /**
32
27
  * Add an event to a span
33
28
  * @param params Parameters to add an event to a span
34
29
  */
35
- addSpanEvent(params: AddSpanEventRequest): Promise<any>;
30
+ addSpanEvent(params: AddSpanEventRequest): Promise<AddSpanEventResponse>;
36
31
  /**
37
32
  * Add an error to a span
38
33
  * @param params Parameters to add an error to a span
39
34
  */
40
- addSpanError(params: AddSpanErrorRequest): Promise<any>;
35
+ addSpanError(params: AddSpanErrorRequest): Promise<AddSpanErrorResponse>;
41
36
  /**
42
37
  * Add a hint to a span
43
38
  * @param params Parameters to add a hint to a span
44
39
  */
45
- addSpanHint(params: AddSpanHintRequest): Promise<any>;
40
+ addSpanHint(params: AddSpanHintRequest): Promise<AddSpanHintResponse>;
46
41
  }
47
42
 
48
43
  interface Metadata {