dynatrace-extensions / dt-extensions-python-sdk

Dynatrace Python Extensions SDK
https://dynatrace-extensions.github.io/dt-extensions-python-sdk/
MIT License
8 stars 1 forks source link

Small changes to the template #72

Closed radu-stefan-dt closed 3 months ago

radu-stefan-dt commented 3 months ago

Proposing a couple of changes I find myself adding to every extension.

Namely, change the initialize function from:

    def initialize(self):
        self.extension_name = "%extension_name%"

to

    def initialize(self):
        self.extension_name = "%extension_name%"
        self.extension_version = self.activation_config.version
        self.logger.name = self.extension_name
        self.logger.info(f"Initializing {self.extension_name} {self.extension_version}")

Changes:

  1. Set the extension version based on activation config version
  2. Set the logger name to the extension name (often dynatrace_extension.sdk.extension is longer and less relevant than the extension name)
  3. Log by default the extension along with its version. This helps in troubleshooting and is more relevant than the SDK version which is currently logged instead.
radu-stefan-dt commented 3 months ago

The existing log message already did what I wanted, however the self.extension_name part would always be empty since __init__ sets it to "" and implies that user must set it. I don't understand why, so I made a further change...

I moved name as a parameter on __init__. So our template now passes this into the object creation:

def main():
    ExtensionImpl(name="%extension_name%").run()

Not sure if you also agree with it?