Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTTP GetSettings #527

Merged
merged 5 commits into from
Dec 17, 2024
Merged

Use HTTP GetSettings #527

merged 5 commits into from
Dec 17, 2024

Conversation

raphael-theriault-swi
Copy link
Member

This switches from gRPC to HTTP as the protocol to obtain sampling settings from the collector. More logic can be shared with the Lambda JSON sampler, and we drop all dependencies on gRPC and the apm-proto package. Some changes were also made to allow running the sampler in a browser context.

@raphael-theriault-swi raphael-theriault-swi requested a review from a team as a code owner December 12, 2024 16:48
Comment on lines +17 to +18
import { hmac } from "@noble/hashes/hmac"
import { sha1 } from "@noble/hashes/sha1"
Copy link
Member Author

@raphael-theriault-swi raphael-theriault-swi Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pure JavaScript implementations that work in the browser. noble is routinely audited and probably the best regarded crypto implementation for JavaScript.

@@ -68,7 +68,7 @@ export class AppopticsInboundMetricsProcessor
method: meta.method,
status: meta.status,
url: meta.url,
domain: meta.hostname,
domain: null,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produced unexpected transaction names.

grpc_proxy: config.proxy ?? "",
reporter: "ssl",
metric_format: 1,
metric_format: config.appoptics ? 1 : 2,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make legacy mode better compatible with SWO.

Comment on lines 75 to 88
const collector = z.string().transform((c, ctx) => {
if (!/^https?:/.test(c)) {
c = `https://${c}`
}
try {
return fs.readFile(p, "utf-8")
return new URL(c)
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: (err as Error).message,
})
return z.NEVER
}
})
Copy link
Member Author

@raphael-theriault-swi raphael-theriault-swi Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse the collector directly to a URL object, which will catch some errors early if it's set to a nonsensical value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like using proper variable names would help with readability and providing context here?

Comment on lines +209 to 214
headers: Record<string, string>
otlp: {
tracesEndpoint?: string
metricsEndpoint?: string
logsEndpoint?: string
headers: Record<string, string>
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers field moved out of otlp since they're now also used by the sampler !

Copy link

@cleverchuk cleverchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 75 to 88
const collector = z.string().transform((c, ctx) => {
if (!/^https?:/.test(c)) {
c = `https://${c}`
}
try {
return fs.readFile(p, "utf-8")
return new URL(c)
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: (err as Error).message,
})
return z.NEVER
}
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like using proper variable names would help with readability and providing context here?

.replace(/^apm\.collector\./, "https://otel.collector.")
.concat(ENDPOINTS.traces),
metricsEndpoint:
otel.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ??
otel.OTEL_EXPORTER_OTLP_ENDPOINT?.concat(ENDPOINTS.metrics) ??
raw.collector
raw.collector.hostname
.replace(/^apm\.collector\./, "https://otel.collector.")
Copy link

@cleverchuk cleverchuk Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very clever! however, it looks like https://apm.collector... would be skipped?

}

/** Settings update loop */
#loop() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this would be a nice use case for web workers in browser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wish OTel actually offloaded most processing to a worker but as it is most of the code needs to run on the main worker and having just this loop run in a separate worker and communicate with the main one would add a lot of complexity for not much of a payoff.

@raphael-theriault-swi raphael-theriault-swi merged commit b5bb329 into main Dec 17, 2024
38 checks passed
@raphael-theriault-swi raphael-theriault-swi deleted the NH-98076 branch December 17, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants