Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Dec 5, 2023
1 parent 116112a commit dd05fc1
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions packages/autometrics/src/exporter-prometheus/PrometheusExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,32 @@ export class PrometheusExporter extends MetricReader {
this._abortController = new AbortController();
const { signal } = this._abortController;

this._server = Deno.serve({ hostname, port, signal, onError }, async (request) => {
if (new URL(request.url).pathname !== "/metrics") {
return new Response("not found", { status: 404 });
}

try {
const { resourceMetrics, errors } = await this.collect();
if (errors.length) {
amLogger.trace(
"PrometheusExporter: metrics collection errors",
...errors,
);
this._server = Deno.serve(
{ hostname, port, signal, onError },
async (request) => {
if (new URL(request.url).pathname !== "/metrics") {
return new Response("not found", { status: 404 });
}

return new Response(serializer.serialize(resourceMetrics), {
headers: HEADERS,
});
} catch (error) {
return new Response(`# failed to export metrics: ${error}`, {
headers: HEADERS,
});
}
});
try {
const { resourceMetrics, errors } = await this.collect();
if (errors.length) {
amLogger.trace(
"PrometheusExporter: metrics collection errors",
...errors,
);
}

return new Response(serializer.serialize(resourceMetrics), {
headers: HEADERS,
});
} catch (error) {
return new Response(`# failed to export metrics: ${error}`, {
headers: HEADERS,
});
}
},
);

amLogger.debug(
`Prometheus exporter server started: ${hostname}:${port}/metrics`,
Expand Down

0 comments on commit dd05fc1

Please sign in to comment.