question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception: Instrumentation key was required but not provided

See original GitHub issue

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 10.14.2
  • Python version: 3.7

Describe the problem

Can’t run the docker image: an exception occurs that is related to Azure. It might be due to https://github.com/chakki-works/doccano/pull/72

Source code / logs

To reproduce docker run -p 8080:80 doccano:1

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/doccano/app/app/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 136, in __init__
    self.load_middleware()
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 36, in load_middleware
    mw_instance = middleware(handler)
  File "/usr/local/lib/python3.6/site-packages/applicationinsights/django/middleware.py", line 109, in __init__
    self._client = common.create_client(self._settings)
  File "/usr/local/lib/python3.6/site-packages/applicationinsights/django/common.py", line 74, in create_client
    client = applicationinsights.TelemetryClient(aisettings.ikey, channel)
  File "/usr/local/lib/python3.6/site-packages/applicationinsights/TelemetryClient.py", line 28, in __init__
    raise Exception('Instrumentation key was required but not provided')
Exception: Instrumentation key was required but not provided

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Hironsancommented, Feb 5, 2019

Problem

I found the cause. In line 71 of applicationinsights/django/common.py, there is the following logic:

ikey = aisettings.ikey
if ikey is None:
    return dummy_client("No ikey specified")

where ikey is assigned according to AZURE_APPINSIGHT_IKEY.

If there is no AZURE_APPINSIGHT_IKEY in environment variables, ikey is None. It doesn’t cause any problems. But if there is AZURE_APPINSIGHT_IKEY with empty string, ikey is not None. As a result, the exception is raised in line 74.

client = applicationinsights.TelemetryClient(aisettings.ikey, channel)

Solution

I came up with two solutions.

Solution1: Update settings.py

The problem is caused due to an empty string. So if AZURE_APPINSIGHTS_IKEY is empty, it will be converted to None in settings.py:

AZURE_APPINSIGHTS_IKEY = os.getenv('AZURE_APPINSIGHTS_IKEY')
APPLICATION_INSIGHTS = {
    'ikey': AZURE_APPINSIGHTS_IKEY if AZURE_APPINSIGHTS_IKEY else None,
}

Solution2: Delete AZURE_APPINSIGHT_IKEY from Dockerfile and pass it when executing docker run command

First, delete AZURE_APPINSIGHTS_IKEY from Dockerfile:

# Delete
# ENV AZURE_APPINSIGHTS_IKEY=""

Then pass it to a docker container when executing docker run command:

$ docker run -p 8000:80 -e AZURE_APPINSIGHTS_IKEY=SOMEKEY doccano
1reaction
fabrichtercommented, Feb 4, 2019

I managed to circumvent the issue by commenting out ENV AZURE_APPINSIGHTS_IKEY="" in the Dockerfile. Hope this helps as a temporary workaround and in finding the underlying issue. My guess would be that this is related to #76

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception: Instrumentation key was required but not provided
Solution · Solution1: Update settings.py · Solution2: Delete AZURE_APPINSIGHT_IKEY from Dockerfile and pass it when executing docker run command.
Read more >
Application Insights 'invalid instrumentation key' when using ...
It works fine if i give it an instrumentation key from the regular azure cloud, but if i give it one from the...
Read more >
Connection strings in Application Insights - Azure Monitor
This article shows how to use connection strings.
Read more >
What happens if I do not provide instrumentation key in azure ...
If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are...
Read more >
Writing Your Code - Application Insights Succinctly Ebook
This uses the instrumentation key present in the ApplicationInsights.config file. However, since InstrumentationKey is a property of this class, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found