Moleculer: Service.currentContext is undefined

Created on 13 Feb 2020  路  4Comments  路  Source: moleculerjs/moleculer

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I'm reporting the issue to the correct repository

Current Behavior

Service.currentContext is undefined, no documentation update for this breaking change, no information in Changelog or migration guide

Expected Behavior

Failure Information

in moleculer sources it seems commented
https://github.com/moleculerjs/moleculer/blob/master/src/service.js#L421
https://github.com/moleculerjs/moleculer/blob/master/src/service-broker.js#L1549
https://github.com/moleculerjs/moleculer/blob/master/src/service-broker.js#L190

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

Reproduce code snippet

const broker = new ServiceBroker({
    logger: console,
    transporter: "NATS"
});

broker.createService({
    name: "test",
    actions: {
        empty(ctx) {
            this.logger.info(this.currentContext)
            return "Hello"
        }
    }
});

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Moleculer version: 0.14.1
  • NodeJS version: v13.2.0
  • Operating System: ubuntu
High Bug

All 4 comments

Hi @kesslerdev thanks for reporting. Unfortunately we had to remove the currentContext due to huge performance impact caused by async_hooks. I've removed the reference about currentContext from the docs to avoid confusing the users and will do the same in the changelog.

This also breaks the EventLegacyTraceExporter because getCurrentContext() has been removed.

const ctx = this.broker.getCurrentContext();
        if (ctx)
            this.processExtraMetrics(ctx, payload);

Ohh, nice catch!

Fixed in 09cf905bd75eaa67995026ad886002b4e5863197

Was this page helpful?
0 / 5 - 0 ratings