Skip to content

Commit cda4d90

Browse files
solonkoolesyaOlesia Solonko
andauthored
revert app_insight for backend (#44)
Co-authored-by: Olesia Solonko <olesia.solonko@ngi.no>
1 parent b706b45 commit cda4d90

5 files changed

Lines changed: 3 additions & 164 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ When deploying in different environments (local, Kubernetes, etc.), the followin
2929
- `PYGEOAPI_SERVER_URL`: The external URL where pygeoapi will be accessible. This is used to generate correct links in the API responses.
3030
- For local development: `http://localhost:5000`
3131
- For Kubernetes/production: Your domain, e.g., `https://your-domain.com/api`
32-
- `APPLICATIONINSIGHTS_CONNECTION_STRING`: Connection string to Azure Application Insights. If not specifies, telemetry disabled, no user statistic gathered.
3332

3433
#### Frontend:
3534

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ services:
5252
- "8080:80"
5353
environment:
5454
- API_BASE_URL=http://backend-local:5000
55-
- APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=b4d987bc-1712-4026-aafb-f590fd854ab3;IngestionEndpoint=https://norwayeast-0.in.applicationinsights.azure.com/;LiveEndpoint=https://norwayeast.livediagnostics.monitor.azure.com/;ApplicationId=9fc4692c-7609-4abb-b547-49203ac14d4a
5655
depends_on:
5756
- backend-local
5857
profiles:

pygeoapi/docker/Dockerfile.pygeoapi

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ RUN apt-get update \
2121
zlib1g-dev \
2222
libprotobuf-dev \
2323
protobuf-compiler \
24-
python3-venv \
2524
&& git clone https://github.com/mapbox/tippecanoe.git /tmp/tippecanoe \
2625
&& cd /tmp/tippecanoe \
2726
&& make -j \
@@ -31,13 +30,6 @@ RUN apt-get update \
3130
&& apt-get clean \
3231
&& rm -rf /var/lib/apt/lists/*
3332

34-
RUN python3 -m venv /opt/venv \
35-
&& /opt/venv/bin/python -m pip install --upgrade pip setuptools wheel
36-
ENV PATH="/opt/venv/bin:$PATH"
37-
38-
# Install Application Insights for Python
39-
RUN pip install opencensus-ext-azure opencensus-ext-flask opencensus-ext-requests
40-
4133
# Build version string
4234
ARG REPO_VERSION
4335
RUN PY_VER=$(python3 -c 'import pkg_resources;print(pkg_resources.get_distribution("pygeoapi").version)') \
@@ -46,9 +38,6 @@ RUN PY_VER=$(python3 -c 'import pkg_resources;print(pkg_resources.get_distributi
4638
# Create readiness indicator directory
4739
RUN mkdir -p /tmp/health
4840

49-
# Add Application Insights instrumentation script
50-
COPY pygeoapi/docker/appinsights_init.py /appinsights_init.py
51-
5241
# Add init script
5342
COPY pygeoapi/docker/init.sh /init.sh
5443
RUN chmod +x /init.sh
@@ -57,9 +46,6 @@ RUN chmod +x /init.sh
5746
COPY pygeoapi/docker/healthcheck.sh /healthcheck.sh
5847
RUN chmod +x /healthcheck.sh
5948

60-
# Environment variable for Application Insights
61-
ENV APPLICATIONINSIGHTS_CONNECTION_STRING=""
62-
6349
HEALTHCHECK --interval=15s --timeout=10s --start-period=180s --retries=10 CMD ["/healthcheck.sh"]
6450

6551
ENTRYPOINT ["/init.sh"]

pygeoapi/docker/appinsights_init.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

pygeoapi/docker/init.sh

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ fi
2020
PYGEOAPI_VERSION=$(pygeoapi --version 2>&1)
2121
echo "$(get_timestamp) [init] PyGeoAPI version: $PYGEOAPI_VERSION"
2222

23-
# Check Application Insights configuration
24-
if [ -n "$APPLICATIONINSIGHTS_CONNECTION_STRING" ]; then
25-
echo "$(get_timestamp) [init] Application Insights connection string found, enabling telemetry"
26-
export PYTHONPATH="/appinsights_init.py:$PYTHONPATH"
27-
else
28-
echo "$(get_timestamp) [init] No Application Insights connection string found, running without telemetry"
29-
fi
30-
3123
# Remove any existing readiness indicator
3224
rm -f /tmp/health/init_complete
3325
echo "$(get_timestamp) [init] Removed any existing readiness indicators"
@@ -52,58 +44,6 @@ mkdir -p /tmp/health
5244
touch /tmp/health/init_complete
5345
echo "$(get_timestamp) [init] Initialization complete"
5446

55-
# Start pygeoapi with Application Insights if configured
56-
if [ -n "$APPLICATIONINSIGHTS_CONNECTION_STRING" ]; then
57-
echo "$(get_timestamp) [init] Starting pygeoapi service with Application Insights"
58-
59-
# First, generate the OpenAPI document that pygeoapi needs
60-
echo "$(get_timestamp) [init] Generating OpenAPI document"
61-
pygeoapi openapi generate /pygeoapi/local.config.yml --output-file /tmp/openapi.yml
62-
63-
# Create a startup script that integrates Application Insights
64-
cat > /tmp/start_with_insights.py << 'EOF'
65-
import os
66-
import sys
67-
68-
# Add root to Python path to import appinsights_init
69-
sys.path.insert(0, '/')
70-
71-
try:
72-
import appinsights_init
73-
print("[start_with_insights] Application Insights module loaded")
74-
75-
# Import prebuilt Flask app instance
76-
from pygeoapi.flask_app import APP as app
77-
print("[start_with_insights] Flask app imported successfully")
78-
79-
# Setup Application Insights telemetry
80-
appinsights_init.setup_app_insights(app)
81-
print("[start_with_insights] Application Insights integrated")
82-
83-
except ImportError as e:
84-
print(f"[start_with_insights] ImportError: {e}")
85-
sys.exit(1)
86-
87-
except Exception as e:
88-
print(f"[start_with_insights] Error during telemetry setup: {e}")
89-
import traceback
90-
traceback.print_exc()
91-
92-
# Run the app (development mode only)
93-
if __name__ == '__main__':
94-
print("[start_with_insights] Starting Flask app")
95-
app.run(host='0.0.0.0', port=5000)
96-
97-
EOF
98-
99-
# Execute the Application Insights setup (but don't start the app yet)
100-
python3 /tmp/start_with_insights.py
101-
102-
else
103-
echo "$(get_timestamp) [init] Starting pygeoapi service without Application Insights"
104-
echo "$(get_timestamp) [init] Generating OpenAPI document"
105-
pygeoapi openapi generate /pygeoapi/local.config.yml --output-file /tmp/openapi.yml
106-
# Start the pygeoapi service
107-
echo "$(get_timestamp) [init] Starting pygeoapi service"
108-
exec /entrypoint.sh "$@"
109-
fi
47+
# Start the pygeoapi service
48+
echo "$(get_timestamp) [init] Starting pygeoapi service"
49+
exec /entrypoint.sh "$@"

0 commit comments

Comments
 (0)