Effect CommunityEC
Effect Community2y ago
71 replies
addamsson

Troubleshooting Effect-Prometheus Integration

I'm trying to integrate Effect with Prometheus and it seems that I'm not doing something properly. I have a counter:

export const SchedulerJobsScheduled = Metric.counter(
    "Scheduler.Jobs.Scheduled",
    {
        description: "The number of jobs that were scheduled.",
        bigint: true,
        incremental: true,
    },
);

and I increment this in my code:
yield* _(
    incrementCounter(SchedulerJobsScheduled),
);


with a function I created:
export const incrementCounter = (counter: Metric.Counter<bigint>) => {
    console.log("Incrementing counter");
    return counter(succeed(BigInt(1)));
};

When I run my app I can see "Incrementing counter" printed to the console, but the metric reader I provided is not called:
const NodeSdkLive = NodeSdk.layer(() => ({
    resource: { serviceName: "Larisel" },
    spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter()),
    metricReader: new PrometheusExporter({ port: 9464 })
}));

Note that I wrapped PrometheusExporter to check whether it is an infrastructure issue, and I can see that the only function that is called is setMetricProducer, and no metrics are sent to the PrometheusExporter.

I add the NodeSdkLive to my services, and create a runtime out of it. Is this supposed to work?
export const ServicesLive: Layer.Layer<MyServices, ConfigError> =
    Layer.mergeAll(
        // ...
        NodeSdkLive,
    );

export const MY_RUNTIME = ManagedRuntime.make(ServicesLive);
Was this page helpful?