Skip to content

Commit bbb7976

Browse files
committed
update example
1 parent e5e6635 commit bbb7976

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

example/opentelemetry/opentelemetry.mjs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "dotenv/config";
2-
import { CredentialsMethod, FgaApiValidationError, OpenFgaClient, TelemetryAttribute, TelemetryConfiguration } from "@openfga/sdk";
2+
import { CredentialsMethod, FgaApiValidationError, OpenFgaClient, TelemetryAttribute, TelemetryConfiguration, TelemetryMetric } from "@openfga/sdk";
33

44
let credentials;
55
if (process.env.FGA_CLIENT_ID) {
@@ -14,27 +14,40 @@ if (process.env.FGA_CLIENT_ID) {
1414
};
1515
}
1616

17-
// define desired telemetry options
18-
const counterCredentialsRequestAttributes = new Set([
19-
TelemetryAttribute.HttpHost,
20-
TelemetryAttribute.HttpResponseStatusCode,
21-
TelemetryAttribute.UserAgentOriginal,
22-
TelemetryAttribute.FgaClientRequestClientId
23-
]);
24-
25-
const histogramRequestDurationAttributes = TelemetryConfiguration.validAttriburtes;
26-
const histogramQueryDurationAttributes = TelemetryConfiguration.validAttriburtes;
27-
2817
const telemetryConfig = {
2918
metrics: {
30-
counterCredentialsRequest: {
31-
attributes: counterCredentialsRequestAttributes
19+
[TelemetryMetric.CounterCredentialsRequest]: {
20+
attributes: new Set([
21+
TelemetryAttribute.UrlScheme,
22+
TelemetryAttribute.UserAgentOriginal,
23+
TelemetryAttribute.HttpRequestMethod,
24+
TelemetryAttribute.FgaClientRequestClientId,
25+
TelemetryAttribute.FgaClientRequestStoreId,
26+
TelemetryAttribute.FgaClientRequestModelId,
27+
TelemetryAttribute.HttpRequestResendCount,
28+
])
3229
},
33-
histogramRequestDuration: {
34-
attributes: histogramRequestDurationAttributes
30+
[TelemetryMetric.HistogramRequestDuration]: {
31+
attributes: new Set([
32+
TelemetryAttribute.HttpResponseStatusCode,
33+
TelemetryAttribute.UserAgentOriginal,
34+
TelemetryAttribute.FgaClientRequestMethod,
35+
TelemetryAttribute.FgaClientRequestClientId,
36+
TelemetryAttribute.FgaClientRequestStoreId,
37+
TelemetryAttribute.FgaClientRequestModelId,
38+
TelemetryAttribute.HttpRequestResendCount,
39+
])
3540
},
36-
histogramQueryDuration: {
37-
attributes: histogramQueryDurationAttributes
41+
[TelemetryMetric.HistogramQueryDuration]: {
42+
attributes: new Set([
43+
TelemetryAttribute.HttpResponseStatusCode,
44+
TelemetryAttribute.UserAgentOriginal,
45+
TelemetryAttribute.FgaClientRequestMethod,
46+
TelemetryAttribute.FgaClientRequestClientId,
47+
TelemetryAttribute.FgaClientRequestStoreId,
48+
TelemetryAttribute.FgaClientRequestModelId,
49+
TelemetryAttribute.HttpRequestResendCount,
50+
])
3851
}
3952
}
4053
};

0 commit comments

Comments
 (0)