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.

FileExistsError: [Errno 17] File exists: '/root/.opencensus/.azure/gunicorn' when I try to run Docker

See original GitHub issue

Hello there,

I’m currently having the following problem: I have an API, and I want to use Opencensus to export my exceptions to Azure’s Application Insights, but, when I try to run it inside of a Docker Container this problem appears:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
...

File "/app/opensensus_mid.py", line 39, in <module>
    connection_string=connection_string))
  File "/usr/local/lib/python3.7/site-packages/opencensus/ext/azure/log_exporter/__init__.py", line 127, in __init__
    retention_period=self.options.storage_retention_period,
  File "/usr/local/lib/python3.7/site-packages/opencensus/ext/azure/common/storage.py", line 90, in __init__
    self._maintenance_routine(silent=False)
  File "/usr/local/lib/python3.7/site-packages/opencensus/ext/azure/common/storage.py", line 112, in _maintenance_routine
    os.makedirs(self.path)
  File "/usr/local/lib/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/root/.opencensus/.azure/gunicorn'

Describe your environment.

  • Python 3.8.0 (default, Nov 6 2019, 16:00:02)
  • Docker:
Client:
 Version:      17.03.1-ce-rc1
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   3476dbf
 Built:        Wed Mar 15 20:33:22 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.1-ce-rc1
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   3476dbf
 Built:        Wed Mar 15 20:28:18 2017
 OS/Arch:      linux/amd64
  • Opencensus opencensus==0.7.5 opencensus-ext-azure==1.0.0

  • FastAPI: fastapi==0.42.0 uvicorn==0.10.8 gunicorn==20.0.0

Steps to reproduce. I’ve created an “Opencensus middleware” for FastAPI, the code can be found at this link. All I do is call it inside FastAPI middleware.

@app.middleware("http")
async def opencensus_tracking(request: Request, call_next):
    # Creates Tracer and Span (Request)
    opencensus_instance._before_request(request=request)

    # Execute the calling method and then get the result
    response = await call_next(request)

    # Send the status of `responce`
    opencensus_instance._after_request(response=response)

    # Closes the Span and finish the trace
    opencensus_instance.tracer_instance.end_span()
    opencensus_instance.tracer_instance.finish()
    return response


UPDATE:

Okay, I’ve found the reason that this error is occuring, but I don’t know how to solve it (completely).

This problem occurs because I’m trying to run opencensus in a multi-worker env. To solve it, I changed os.makedirs(self.path) to os.makedirs(self.path, exist_ok=True), but exist_ok=True is not compatible with Python 2. Can anybody help me to solve it? I would like to make a PR to this solution.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jeremy010203commented, Dec 6, 2019

Hi @RenanAlonkin , Got the same issue on my docker webapp on Azure.

I have found a workaround, you can specify a storage_path when creating the AzureExporter object:

AzureExporter(
    connection_string=f'InstrumentationKey={telemetry_key}',
    storage_path=os.path.join(
        os.path.expanduser('~'),
        '.opencensus',
        '.azure',
        str(uuid.uuid4()),
        os.path.basename(sys.argv[0]) or '.console',
    )
)

It creates a folder with unique id per thread in the .azure folder (inspired from the default value of storage_path). I am not sure that uuid4 is a good solution but it seems to work just fine.

1reaction
renan-alonkincommented, Dec 6, 2019

To be honest, no, I’ve created a workaround for my project. It does not look good, but it works. What jeremy posted looks like it will work, when I have time I will try to use it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FileExistsError Errno 17 -- I have no clue why this error is ...
The exception is thrown from mkdirs if the dir you're trying to create already exists. Its ment to notify you of that fact....
Read more >
How to Fix and Debug Docker Containers Like a Superhero
Take the container's default command and attempt to run it again. ... Inspect the entrypoint.sh file to confirm our desired command exists.
Read more >
Debugging a weird 'file not found' error - Julia Evans
Seems like it should work, right? But when I try to run /app/serve , this happens: $ docker build . $ docker run...
Read more >
Container permission denied: How to diagnose this error
You can diagnose this by telling the user to attempt to run the container as root, which would match up to the default...
Read more >
Running under Docker - Node-RED
This has the advantage that you don't need to know/specify which architecture you are running on and makes docker run commands and docker...
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