dynatrace-oss / OneAgent-SDK-Python-AutoInstrumentation

autodynatrace, a python library that implements automatic instrumentation using the OneAgent SDK for Python
Other
62 stars 28 forks source link

WARNING autodynatrace - init: Could not initialize the OneAgent SDK #77

Closed samuelbernardy closed 1 year ago

samuelbernardy commented 1 year ago

(will provide code from instrumented app shortly in comments)

Dynatrace image Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2022
SHELL ["powershell.exe", "-c"]
ENV ONEAGENT_PATH="/OneAgent"
ENV DT_ONEAGENT_OPTIONS="flavor=default&arch=x86&include=sdk"
COPY ./sdkInstaller.zip /
COPY ./entrypoint.ps1 /
ENTRYPOINT c:\entrypoint.ps1

Here is the entrypoint.ps1 script as well:

Write-Host "Unpacking agent..."
Expand-Archive -Path "C:\sdkInstaller.zip" -DestinationPath "C:\OneAgent" -Force
Write-Host "Configuring agent..."
$manifest = Get-Content "C:\OneAgent\manifest.json" | ConvertFrom-Json
$config = New-Item -Path "C:\OneAgent\agent\conf" -Name "standalone.conf" -Force
Add-Content -Path $config -Value "tenant $($manifest.tenantUUID)"
Add-Content -Path $config -Value "tenanttoken $($manifest.tenantToken)"
Add-Content -Path $config -Value "server $($manifest.communicationEndpoints -Join ';')"
Add-Content -Path $config -Value "storage C:\OneAgent"
Add-Content -Path $config -Value "loglevelcon NONE"

The Invoke-WebRequest PowerShell cmdlet was used to obtain the SDK binaries, which are being built directly into the image:

Invoke-WebRequest -Uri {Dynatrace Pre-Prod API URL}/api/v1/deployment/installer/agent/windows/paas/latest?Api-Token=xxxxxxxxxxxxxxx&flavor=default&arch=x86&include=sdk -OutFile "sdkInstaller.zip"

  1. Steps to reproduce:

Add initContainer details in deployment YAML containing Dynatrace image:

initContainers:
  - resources:
      limits:
        cpu: '1'
        memory: 2Gi
      requests:
        cpu: 500m
        memory: 1Gi
    terminationMessagePath: /dev/termination-log
    name: install-oneagent
    command:
      - powershell.exe
    securityContext:
      windowsOptions:
        runAsUserName: ContainerUser
    imagePullPolicy: Always
    volumeMounts:
      - name: oneagent
        mountPath: 'C:\OneAgent'
    terminationMessagePolicy: File
    image: 'xxxx/xxxx/dynatrace-oneagent:sdk-0.1.0-ltsc2022'
    args:
      - '-c'
      - 'c:/entrypoint.ps1'

Deploy YAML to OpenShift/Kubernetes using kubectl: kubectl apply -f deploy.yaml

  1. Text Output
[33;1mVERBOSE: Executing Set-RuntimeSecrets[0m
[33;1mVERBOSE: Set-RuntimeSecrets: Started[0m
Updated property [core/project].
[33;1mVERBOSE: Set-RuntimeSecrets: Completed[0m
<Source>EventLog</Source><Time>2023-05-26T17:45:43.000Z</Time><LogEntry><Channel>Application</Channel><Level>Information</Level><EventId>5617</EventId><Message>Windows Management Instrumentation Service subsystems initialized successfully</Message></LogEntry>
true
false
[33;1mVERBOSE: Entrypoint is done! Executing 'python ./app.py'[0m
2023-05-26 17:46:03,944: 27884 WARNING autodynatrace - init: Could not initialize the OneAgent SDK, AgentState: 3
* Serving Flask app 'app'
* Debug mode: off
2023-05-26 17:46:07 | INFO >>> {__main__} >> [-] Triggered and started from 'main' driver.
<Source>EventLog</Source><Time>2023-05-26T17:46:10.000Z</Time><LogEntry><Channel>System</Channel><Level>Information</Level><EventId>7036</EventId><Message>The DiagHost service entered the running state.</Message></LogEntry>
<Source>EventLog</Source><Time>2023-05-26T17:46:10.000Z</Time><LogEntry><Channel>System</Channel><Level>Information</Level><EventId>7036</EventId><Message>The DiagHost service entered the stopped state.</Message></LogEntry>
<Source>EventLog</Source><Time>2023-05-26T17:46:10.000Z</Time><LogEntry><Channel>System</Channel><Level>Error</Level><EventId>7023</EventId><Message>The DiagHost service terminated with the following error:   The RPC server is unavailable.</Message></LogEntry>
<Source>EventLog</Source><Time>2023-05-26T17:46:10.000Z</Time><LogEntry><Channel>System</Channel><Level>Error</Level><EventId>7031</EventId><Message>The DiagHost service terminated unexpectedly.  It has done this 2 time(s).  The following corrective action will be taken in 120000 milliseconds: Restart the service.</Message></LogEntry>
2023-05-26 17:46:07 | INFO >>> [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:443/
* Running on http://xxx.xx.x.xx:443/
2023-05-26 17:46:07 | INFO >>> [33mPress CTRL+C to quit[0m
2023-05-26 17:46:13 | INFO >>> {consume_hex_file_convert_publish_vbf_file} >> [-] Triggering 'main' from first web request
2023-05-26 17:46:13 | INFO >>> {main} >> [-] Got environment variables
2023-05-26 17:46:13 | INFO >>> {home} >> [-] Up and running
2023-05-26 17:46:13 | INFO >>> 127.0.0.1 - - [26/May/2023 17:46:13] "GET / HTTP/1.1" 200 -
2023-05-26 17:46:13 | INFO >>> {return_consumer_client} >> [-] Consumer Client Object : <autodynatrace.wrappers.confluent_kafka.wrapper.Consumer object at 0x00000244C10F7468>
2023-05-26 17:46:13 | INFO >>> {main} >> [-] Subscribed to Kafka Topic 'xxxxxxx-xxxx-xxxx'
  1. Environment details

OpenShift 4.11 (running in GCP), Kubernetes version v1.24.6+263df15, Windows container info: Windows Server 2022 [Version 10.0.20348.1668] Python version 3.7.0

dlopes7 commented 1 year ago

Agent State 3 means the OneAgent SDK module was not even found/loaded. This is not an issue with this library, please open a support ticket with Dynatrace, after doing the troubleshooting documented here: https://github.com/Dynatrace/OneAgent-SDK-for-Python#troubleshooting