@shivaedev/platform 0.13.0 → 0.14.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +25 -4
  3. package/dist/server/appHost.d.ts +9 -16
  4. package/dist/server/appHost.d.ts.map +1 -1
  5. package/dist/server/appHost.js +5 -2
  6. package/dist/server/appHost.js.map +1 -1
  7. package/dist/server/appHostHttp.d.ts +3 -2
  8. package/dist/server/appHostHttp.d.ts.map +1 -1
  9. package/dist/server/appHostHttp.js +5 -1
  10. package/dist/server/appHostHttp.js.map +1 -1
  11. package/dist/server/databaseLayer.d.ts +9 -2
  12. package/dist/server/databaseLayer.d.ts.map +1 -1
  13. package/dist/server/databaseLayer.js +5 -2
  14. package/dist/server/databaseLayer.js.map +1 -1
  15. package/dist/server/healthRoute.d.ts +3 -0
  16. package/dist/server/healthRoute.d.ts.map +1 -0
  17. package/dist/server/healthRoute.js +18 -0
  18. package/dist/server/healthRoute.js.map +1 -0
  19. package/dist/server/otlpHttpClient.d.ts +4 -0
  20. package/dist/server/otlpHttpClient.d.ts.map +1 -0
  21. package/dist/server/otlpHttpClient.js +24 -0
  22. package/dist/server/otlpHttpClient.js.map +1 -0
  23. package/dist/server/otlpTracing.d.ts.map +1 -1
  24. package/dist/server/otlpTracing.js +6 -3
  25. package/dist/server/otlpTracing.js.map +1 -1
  26. package/dist/server/redactOtlpUrl.d.ts +2 -0
  27. package/dist/server/redactOtlpUrl.d.ts.map +1 -0
  28. package/dist/server/redactOtlpUrl.js +41 -0
  29. package/dist/server/redactOtlpUrl.js.map +1 -0
  30. package/dist/server/safeOtlpSerialization.d.ts +2 -1
  31. package/dist/server/safeOtlpSerialization.d.ts.map +1 -1
  32. package/dist/server/safeOtlpSerialization.js +25 -16
  33. package/dist/server/safeOtlpSerialization.js.map +1 -1
  34. package/package.json +17 -7
  35. package/src/server/appHost.ts +41 -29
  36. package/src/server/appHostHttp.ts +26 -2
  37. package/src/server/databaseLayer.ts +17 -7
  38. package/src/server/healthRoute.ts +27 -0
  39. package/src/server/otlpHttpClient.ts +35 -0
  40. package/src/server/otlpTracing.ts +15 -5
  41. package/src/server/redactOtlpUrl.ts +48 -0
  42. package/src/server/safeOtlpSerialization.ts +42 -29
@@ -1,50 +1,63 @@
1
- import { Layer } from "effect";
2
- import { HttpBody } from "effect/http";
1
+ import { Effect, Layer } from "effect";
3
2
  import type { OtlpResource } from "effect/observability";
4
3
  import { OtlpSerialization } from "effect/observability";
4
+ import { redactOtlpUrl } from "#redactOtlpUrl.ts";
5
5
  import { isSensitiveKey, REDACTED, redactText } from "#rpc-server/sensitive.ts";
6
6
 
7
7
  function sensitive(key: string) {
8
8
  return isSensitiveKey(key) || ["db.user", "db.user.name", "db.connection_string"].includes(key.toLowerCase());
9
9
  }
10
- function text(value: string) {
11
- return redactText(value, sensitive).replaceAll(/(?<scheme>\b[a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/giu, `$<scheme>${REDACTED}@`);
10
+ export function redactOtlpText(value: string, key = "") {
11
+ return redactText(redactOtlpUrl(value, key), sensitive);
12
12
  }
13
- function attributeValue(value: OtlpResource.AnyValue): OtlpResource.AnyValue {
13
+ function attributeValue(value: OtlpResource.AnyValue, key: string): OtlpResource.AnyValue {
14
14
  return {
15
15
  ...value,
16
- ...(typeof value.stringValue === "string" ? { stringValue: text(value.stringValue) } : {}),
17
- ...(value.arrayValue ? { arrayValue: { values: value.arrayValue.values.map(attributeValue) } } : {}),
16
+ ...(typeof value.stringValue === "string" ? { stringValue: redactOtlpText(value.stringValue, key) } : {}),
17
+ ...(value.arrayValue ? { arrayValue: { values: value.arrayValue.values.map((item) => attributeValue(item, key)) } } : {}),
18
18
  ...(value.kvlistValue ? { kvlistValue: { values: attributes(value.kvlistValue.values) } } : {}),
19
19
  };
20
20
  }
21
21
  function attributes(values: OtlpResource.KeyValue[]): OtlpResource.KeyValue[] {
22
22
  return values.map(({ key, value }) => ({
23
23
  key,
24
- value: sensitive(key) ? { stringValue: REDACTED } : attributeValue(value),
24
+ value: sensitive(key) ? { stringValue: REDACTED } : attributeValue(value, key),
25
25
  }));
26
26
  }
27
27
 
28
- export const safeOtlpSerialization = Layer.succeed(OtlpSerialization.OtlpSerialization, {
29
- logs: HttpBody.jsonUnsafe,
30
- metrics: HttpBody.jsonUnsafe,
31
- traces: (data) =>
32
- HttpBody.jsonUnsafe({
33
- ...data,
34
- resourceSpans: data.resourceSpans.map((resource) => ({
35
- ...resource,
36
- resource: { ...resource.resource, attributes: attributes(resource.resource.attributes) },
37
- scopeSpans: resource.scopeSpans.map((scope) => ({
38
- ...scope,
39
- spans: scope.spans.map((span) => ({
40
- ...span,
41
- attributes: attributes(span.attributes),
42
- events: span.events.map((event) => ({ ...event, attributes: attributes(event.attributes), name: text(event.name) })),
43
- links: span.links.map((link) => ({ ...link, attributes: attributes(link.attributes) })),
44
- name: text(span.name),
45
- status: { ...span.status, ...(span.status.message === undefined ? {} : { message: text(span.status.message) }) },
28
+ function spanName(span: { readonly name: string; readonly kind: number; readonly attributes: OtlpResource.KeyValue[] }) {
29
+ if (span.kind === 2) {
30
+ const method = span.attributes.find(({ key }) => key === "http.request.method")?.value.stringValue;
31
+ const route = span.attributes.find(({ key }) => key === "http.route")?.value.stringValue;
32
+ if (typeof method === "string") {
33
+ return typeof route === "string" ? `${method} ${route}` : method;
34
+ }
35
+ }
36
+ return span.name;
37
+ }
38
+
39
+ export const safeOtlpSerialization = Layer.effect(
40
+ OtlpSerialization.OtlpSerialization,
41
+ Effect.map(OtlpSerialization.OtlpSerialization, (serialization) => ({
42
+ ...serialization,
43
+ traces: (data) =>
44
+ serialization.traces({
45
+ ...data,
46
+ resourceSpans: data.resourceSpans.map((resource) => ({
47
+ ...resource,
48
+ resource: { ...resource.resource, attributes: attributes(resource.resource.attributes) },
49
+ scopeSpans: resource.scopeSpans.map((scope) => ({
50
+ ...scope,
51
+ spans: scope.spans.map((span) => ({
52
+ ...span,
53
+ attributes: attributes(span.attributes),
54
+ events: span.events.map((event) => ({ ...event, attributes: attributes(event.attributes), name: redactOtlpText(event.name) })),
55
+ links: span.links.map((link) => ({ ...link, attributes: attributes(link.attributes) })),
56
+ name: redactOtlpText(spanName(span)),
57
+ status: { ...span.status, ...(span.status.message === undefined ? {} : { message: redactOtlpText(span.status.message) }) },
58
+ })),
46
59
  })),
47
60
  })),
48
- })),
49
- }),
50
- });
61
+ }),
62
+ })),
63
+ );