1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "telemetry": {
12 "resourceSpans": [
13 {
14 "resource": {
15 "attributes": [
16 {
17 "key": "service.name",
18 "value": {
19 "stringValue": "checkout"
20 }
21 },
22 {
23 "key": "deployment.environment.name",
24 "value": {
25 "stringValue": "demo"
26 }
27 }
28 ]
29 },
30 "scopeSpans": [
31 {
32 "scope": {
33 "name": "io.opentelemetry.http",
34 "version": "2.9.0"
35 },
36 "spans": [
37 {
38 "traceId": "5b8efff798038103d269b633813fc60c",
39 "spanId": "eee19b7ec3c1b174",
40 "name": "GET /api/users/jane.doe@example.com/orders",
41 "kind": 2,
42 "attributes": [
43 {
44 "key": "http.request.method",
45 "value": {
46 "stringValue": "GET"
47 }
48 },
49 {
50 "key": "url.full",
51 "value": {
52 "stringValue": "https://shop.example.com/api/users/jane.doe@example.com/orders?api_key=demo-k3y-0f-fake-shop-9921&page=2"
53 }
54 },
55 {
56 "key": "http.request.header.authorization",
57 "value": {
58 "arrayValue": {
59 "values": [
60 {
61 "stringValue": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyLTQyIiwibmFtZSI6IkphbmUgRG9lIiwiZW1haWwiOiJqYW5lLmRvZUBleGFtcGxlLmNvbSIsImlhdCI6MTcwMDAwMDAwMH0.ZGVtby1zaWduYXR1cmUtbm90LXJlYWw"
62 }
63 ]
64 }
65 }
66 },
67 {
68 "key": "client.address",
69 "value": {
70 "stringValue": "203.0.113.42"
71 }
72 },
73 {
74 "key": "user.id",
75 "value": {
76 "stringValue": "user-42"
77 }
78 },
79 {
80 "key": "app.customer_ref",
81 "value": {
82 "stringValue": "CUST-00012345"
83 }
84 },
85 {
86 "key": "geo.location.lat",
87 "value": {
88 "doubleValue": 42.3314
89 }
90 },
91 {
92 "key": "geo.location.lon",
93 "value": {
94 "doubleValue": -83.0458
95 }
96 }
97 ],
98 "events": [
99 {
100 "name": "exception",
101 "attributes": [
102 {
103 "key": "exception.type",
104 "value": {
105 "stringValue": "OperationalError"
106 }
107 },
108 {
109 "key": "exception.message",
110 "value": {
111 "stringValue": "could not connect to postgres://orders_app:Sup3rS3cretPw@db.internal:5432/orders"
112 }
113 }
114 ]
115 }
116 ],
117 "status": {
118 "code": 2,
119 "message": "upstream payment call failed"
120 }
121 },
122 {
123 "traceId": "5b8efff798038103d269b633813fc60c",
124 "spanId": "aaa19b7ec3c1b175",
125 "parentSpanId": "eee19b7ec3c1b174",
126 "name": "SELECT orders",
127 "kind": 3,
128 "attributes": [
129 {
130 "key": "db.system",
131 "value": {
132 "stringValue": "postgresql"
133 }
134 },
135 {
136 "key": "db.query.text",
137 "value": {
138 "stringValue": "SELECT * FROM customers WHERE email = 'jane.doe@example.com' AND phone = '+1 202-555-0143'"
139 }
140 }
141 ]
142 }
143 ]
144 }
145 ]
146 }
147 ],
148 "resourceLogs": [
149 {
150 "resource": {
151 "attributes": [
152 {
153 "key": "service.name",
154 "value": {
155 "stringValue": "payments"
156 }
157 },
158 {
159 "key": "deployment.environment.name",
160 "value": {
161 "stringValue": "demo"
162 }
163 }
164 ]
165 },
166 "scopeLogs": [
167 {
168 "scope": {
169 "name": "payments.logger"
170 },
171 "logRecords": [
172 {
173 "severityText": "INFO",
174 "body": {
175 "stringValue": "Loaded AWS credentials AKIAIOSFODNN7EXAMPLE from environment"
176 },
177 "attributes": [
178 {
179 "key": "payment.card_number",
180 "value": {
181 "stringValue": "4111 1111 1111 1111"
182 }
183 },
184 {
185 "key": "payment.iban",
186 "value": {
187 "stringValue": "GB82 WEST 1234 5698 7654 32"
188 }
189 }
190 ]
191 },
192 {
193 "severityText": "WARN",
194 "body": {
195 "kvlistValue": {
196 "values": [
197 {
198 "key": "event",
199 "value": {
200 "stringValue": "patient_lookup"
201 }
202 },
203 {
204 "key": "patient",
205 "value": {
206 "kvlistValue": {
207 "values": [
208 {
209 "key": "mrn",
210 "value": {
211 "stringValue": "MRN-00482913"
212 }
213 },
214 {
215 "key": "ssn",
216 "value": {
217 "stringValue": "078-05-1120"
218 }
219 },
220 {
221 "key": "dob",
222 "value": {
223 "stringValue": "1985-03-12"
224 }
225 }
226 ]
227 }
228 }
229 },
230 {
231 "key": "note",
232 "value": {
233 "stringValue": "Patient diagnosis E11.9, prescribed metformin"
234 }
235 }
236 ]
237 }
238 },
239 "attributes": []
240 }
241 ]
242 }
243 ]
244 }
245 ],
246 "resourceMetrics": [
247 {
248 "resource": {
249 "attributes": [
250 {
251 "key": "service.name",
252 "value": {
253 "stringValue": "checkout"
254 }
255 },
256 {
257 "key": "deployment.environment.name",
258 "value": {
259 "stringValue": "demo"
260 }
261 }
262 ]
263 },
264 "scopeMetrics": [
265 {
266 "scope": {
267 "name": "io.opentelemetry.http"
268 },
269 "metrics": [
270 {
271 "name": "http.server.request.duration",
272 "unit": "s",
273 "description": "Duration of HTTP server requests.",
274 "histogram": {
275 "aggregationTemporality": 2,
276 "dataPoints": [
277 {
278 "count": "3",
279 "sum": 0.42,
280 "attributes": [
281 {
282 "key": "http.route",
283 "value": {
284 "stringValue": "/api/users/{id}/orders"
285 }
286 },
287 {
288 "key": "user.email",
289 "value": {
290 "stringValue": "john.smith@example.org"
291 }
292 }
293 ]
294 }
295 ]
296 }
297 }
298 ]
299 }
300 ]
301 }
302 ]
303 },
304 "customPatterns": [
305 {
306 "name": "customer-ref",
307 "pattern": "CUST-[0-9]{8}",
308 "severity": "medium",
309 "action": "hash"
310 }
311 ]
312};
313
314
315const run = await client.actor("michiganpublictech/otel-pii-leak-detector").call(input);
316
317
318console.log('Results from dataset');
319console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
320const { items } = await client.dataset(run.defaultDatasetId).listItems();
321items.forEach((item) => {
322 console.dir(item);
323});
324
325