What am i doing wrong with FastAPI docker-compose.yml and Dockerfile? #873
-
I installed the Docker Standalone: I added a separate requirements file
then I edited my docker files to suit the ones in the documentation: my version: '3.7'
services:
myapp:
container_name: myapp
volumes:
- /home/myubuntu/maindir/myapp:/myapp
depends_on:
- mydb
build: ./myapp
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
POSTGRES_HOST: 172.18.0.6
POSTGRES_PORT: 5432
USER_ACCESS: user
PASS_ACCESS: pass
OTEL_RESOURCE_ATTRIBUTES: service.name=myapp
OTEL_EXPORTER_OTLP_ENDPOINT: "http://0.0.0.0:4317" # Tried "http://localhost:4317" too.
ports:
- "4001:4001"
networks:
clusternetwork:
ipv4_address: 172.18.0.67
links:
- mydb
networks:
clusternetwork:
driver: bridge
volumes:
nginxdata:
driver: local
postgres_data:
driver: local
my FROM python:3.9.9
COPY ./requirements.txt /myapp/requirements.txt
COPY ./dev-requirements.txt /myapp/dev-requirements.txt
RUN /bin/bash -c "python -m pip install --upgrade pip"
RUN pip install --no-cache-dir -r /myapp/requirements.txt
RUN pip install --no-cache-dir -r /myapp/dev-requirements.txt
COPY ./ /myapp
RUN cd myapp
RUN opentelemetry-bootstrap --action=install
RUN cd ..
CMD ["opentelemetry-instrument", "uvicorn", "myapp.main:myapp", "--proxy-headers", "--host", "0.0.0.0", "--port", "4001", "--forwarded-allow-ips", "*", "--log-level", "debug"] # removed --reload SigNoz dashboard is running but I cannot see my app listed. edit: This is my main.py fastapi file from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from .something3 import router_something3
from .something2 import router_something2
from .something1 import router_something1
from .dashboard import router_dashboard
from .login import router_login
# DEV ONLY
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.sdk.trace import TracerProvider
tracer = TracerProvider()
#
# Main app init.
#
myapp = FastAPI(
title = "myapp 2.0",
# docs_url = None
)
#
# Middleware
#
myapp.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
#
# Routes
#
myapp.include_router(router_something3.router)
myapp.include_router(router_something2.router)
myapp.include_router(router_something1.router)
myapp.include_router(router_dashboard.router)
myapp.include_router(router_login.router)
#
# Static files
# (Ref: https://fastapi.tiangolo.com/tutorial/static-files/)
BASE_PATH = Path(__file__).resolve().parent
myapp.mount(str(BASE_PATH / "static"), StaticFiles(directory=str(BASE_PATH / "static")), name="static")
FastAPIInstrumentor.instrument_app(myapp, tracer_provider=tracer, excluded_urls="ping") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
@waldoc89 auto-instrumentation is known to not work well with reload option in many instrumentations. can you try without reloading? |
Beta Was this translation helpful? Give feedback.
@waldoc89 auto-instrumentation is known to not work well with reload option in many instrumentations. can you try without reloading?