Get current plugin Id from Lua

Hi, is it possible to get the subj using PDK?

Thanks in advance

Hi @Alexander_Altshuler,

I’m curious as to why you would like to access the ID of the plugin being executed. Could you elaborate your problem a little?


Sorry for later reply.

I see 2 possible use cases:

  • store per-plugin-instance data on module level
  • self-update configuration of the plugin

For both cases IMO I need to know plugins Id in Lua.


I don’t think this is possible as of today. You could open a feature request if you would like this feature.

You can do this today, but the functionality is not exposed by PDK (although we have plans to do so eventually).

You have to be careful and know what you are doing, or else you are exposing yourself to potential memory leaks (i.e. “non reclaimable references”). Several bundled plugins follow such a pattern, for example:

Which builds and caches per-plugin-configuration (what you refer to as “per-plugin-instance”) state only once, for efficiency purposes:

For your 2 use cases:

  1. We can use a string as the key to storage;
  2. This is not considered a proper design

Thibaultcha’s answer is outdated for the current implementation, as the conf table may be recreated. Also, that solution is not practical for other languages than Lua.

@Wangchong_Zhou suggests using conf.__key__ as the key. And considering how we would use it, the route(where are we) could be enough to tell difference from other instances.

We’ve discussed about adding support to “per plugin instance storage”, and @Wangchong_Zhou thinks it will just be another granularity of kong.cache, and we don’t really need the concept of “per plugin instance storage”.