Skip to content

Commit cfe0bbf

Browse files
committed
Enhance TFO-Python-SDK with OTEL Autoinstrumentation
1 parent 455de2e commit cfe0bbf

38 files changed

+5748
-261
lines changed

.github/workflows/ci.yml

Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
# Copyright (c) 2024-2026 DevOpsCorner Indonesia. All rights reserved.
77
#
88
# This workflow runs tests and linting for the TelemetryFlow Python SDK:
9-
# - Unit tests
10-
# - Integration tests
11-
# - Linting with ruff and mypy
12-
# - Code coverage
9+
# - Unit tests (via Makefile)
10+
# - Integration tests (via Makefile)
11+
# - Linting with ruff and mypy (via Makefile)
12+
# - Code coverage (via Makefile)
13+
#
14+
# Compatible with TFO-Collector v1.1.2 (OCB-native)
1315
#
1416
# =============================================================================
1517

@@ -28,6 +30,7 @@ on:
2830
- 'tests/**'
2931
- 'pyproject.toml'
3032
- 'requirements*.txt'
33+
- 'Makefile'
3134
- '.github/workflows/ci.yml'
3235
pull_request:
3336
branches:
@@ -39,6 +42,7 @@ on:
3942
- 'tests/**'
4043
- 'pyproject.toml'
4144
- 'requirements*.txt'
45+
- 'Makefile'
4246
workflow_dispatch:
4347
inputs:
4448
run_e2e:
@@ -55,6 +59,8 @@ on:
5559
env:
5660
PYTHON_VERSION: '3.12'
5761
PRODUCT_NAME: TelemetryFlow Python SDK
62+
VERSION: '1.1.2'
63+
TFO_COLLECTOR_VERSION: '1.1.2'
5864

5965
permissions:
6066
contents: read
@@ -63,7 +69,7 @@ permissions:
6369

6470
jobs:
6571
# ===========================================================================
66-
# Code Quality - Lint, Format, Type Check
72+
# Code Quality - Lint, Format, Type Check (via Makefile)
6773
# ===========================================================================
6874
lint:
6975
name: Lint & Code Quality
@@ -79,23 +85,17 @@ jobs:
7985
python-version: ${{ env.PYTHON_VERSION }}
8086
cache: 'pip'
8187

82-
- name: Install dependencies
83-
run: |
84-
python -m pip install --upgrade pip
85-
pip install -e ".[dev]"
86-
87-
- name: Check formatting with ruff
88-
run: ruff format --check src/ tests/
88+
- name: Install CI dependencies
89+
run: make ci-deps
8990

90-
- name: Run ruff linter
91-
run: ruff check src/ tests/
91+
- name: Show version info
92+
run: make version
9293

93-
- name: Run mypy type checker
94-
run: mypy src/ --ignore-missing-imports
95-
continue-on-error: true
94+
- name: Run CI lint suite
95+
run: make ci-lint
9696

9797
# ===========================================================================
98-
# Unit Tests
98+
# Unit Tests (via Makefile)
9999
# ===========================================================================
100100
test-unit:
101101
name: Unit Tests (Python ${{ matrix.python-version }})
@@ -116,25 +116,24 @@ jobs:
116116
python-version: ${{ matrix.python-version }}
117117
cache: 'pip'
118118

119-
- name: Install dependencies
120-
run: |
121-
python -m pip install --upgrade pip
122-
pip install -e ".[dev]"
119+
- name: Install CI dependencies
120+
run: make ci-deps
123121

124-
- name: Run unit tests
125-
run: |
126-
pytest tests/unit/ -v --cov=src/telemetryflow --cov-report=xml --cov-report=term-missing
122+
- name: Run unit tests (CI mode)
123+
run: make ci-test-unit
127124

128125
- name: Upload coverage report
129126
if: matrix.python-version == '3.12'
130127
uses: actions/upload-artifact@v4
131128
with:
132129
name: coverage-unit
133-
path: coverage.xml
130+
path: |
131+
coverage-unit.xml
132+
junit-unit.xml
134133
retention-days: 7
135134

136135
# ===========================================================================
137-
# Integration Tests
136+
# Integration Tests (via Makefile)
138137
# ===========================================================================
139138
test-integration:
140139
name: Integration Tests
@@ -151,20 +150,19 @@ jobs:
151150
python-version: ${{ env.PYTHON_VERSION }}
152151
cache: 'pip'
153152

154-
- name: Install dependencies
155-
run: |
156-
python -m pip install --upgrade pip
157-
pip install -e ".[dev]"
153+
- name: Install CI dependencies
154+
run: make ci-deps
158155

159-
- name: Run integration tests
160-
run: |
161-
pytest tests/integration/ -v --cov=src/telemetryflow --cov-report=xml --cov-append || true
156+
- name: Run integration tests (CI mode)
157+
run: make ci-test-integration
162158

163159
- name: Upload coverage report
164160
uses: actions/upload-artifact@v4
165161
with:
166162
name: coverage-integration
167-
path: coverage.xml
163+
path: |
164+
coverage-integration.xml
165+
junit-integration.xml
168166
retention-days: 7
169167
continue-on-error: true
170168

@@ -186,17 +184,15 @@ jobs:
186184
python-version: ${{ env.PYTHON_VERSION }}
187185
cache: 'pip'
188186

189-
- name: Install dependencies
190-
run: |
191-
python -m pip install --upgrade pip
192-
pip install -e ".[dev]"
187+
- name: Install CI dependencies
188+
run: make ci-deps
193189

194190
- name: Run E2E tests
195191
run: |
196192
pytest tests/e2e/ -v || true
197193
198194
# ===========================================================================
199-
# Build Verification - CLI Generators
195+
# Build Verification - CLI Generators (via Makefile)
200196
# ===========================================================================
201197
build:
202198
name: Build & Verify (${{ matrix.os }})
@@ -217,11 +213,20 @@ jobs:
217213
python-version: ${{ env.PYTHON_VERSION }}
218214
cache: 'pip'
219215

220-
- name: Install package
216+
- name: Install package (Unix)
217+
if: matrix.os != 'windows-latest'
218+
run: make deps
219+
220+
- name: Install package (Windows)
221+
if: matrix.os == 'windows-latest'
221222
run: |
222223
python -m pip install --upgrade pip
223224
pip install -e "."
224225
226+
- name: Show version info (Unix)
227+
if: matrix.os != 'windows-latest'
228+
run: make version
229+
225230
- name: Verify CLI generators (Unix)
226231
if: matrix.os != 'windows-latest'
227232
run: |
@@ -259,7 +264,7 @@ jobs:
259264
dir $env:TEMP\test-restapi\test-api
260265
261266
# ===========================================================================
262-
# Security Scan
267+
# Security Scan (via Makefile)
263268
# ===========================================================================
264269
security:
265270
name: Security Scan
@@ -276,29 +281,21 @@ jobs:
276281
python-version: ${{ env.PYTHON_VERSION }}
277282
cache: 'pip'
278283

279-
- name: Install dependencies
280-
run: |
281-
python -m pip install --upgrade pip
282-
pip install bandit safety pip-audit
284+
- name: Install CI dependencies
285+
run: make ci-deps
283286

284-
- name: Run Bandit security linter
285-
run: |
286-
bandit -r src/ -f sarif -o bandit-results.sarif || true
287+
- name: Run security scan (CI mode)
288+
run: make ci-security
287289

288290
- name: Upload Bandit SARIF
289291
uses: github/codeql-action/upload-sarif@v4
290292
if: always()
291293
with:
292-
sarif_file: bandit-results.sarif
293-
continue-on-error: true
294-
295-
- name: Run pip-audit
296-
run: |
297-
pip-audit --ignore-vuln PYSEC-2024-48 || true
294+
sarif_file: bandit-results.json
298295
continue-on-error: true
299296

300297
# ===========================================================================
301-
# Coverage Report
298+
# Coverage Report (via Makefile)
302299
# ===========================================================================
303300
coverage:
304301
name: Coverage Report
@@ -315,23 +312,30 @@ jobs:
315312
python-version: ${{ env.PYTHON_VERSION }}
316313
cache: 'pip'
317314

318-
- name: Install dependencies
319-
run: |
320-
python -m pip install --upgrade pip
321-
pip install coverage
315+
- name: Install CI dependencies
316+
run: make ci-deps
322317

323-
- name: Download unit coverage
324-
uses: actions/download-artifact@v4
318+
- name: Generate coverage report (CI mode)
319+
run: make ci-coverage
320+
321+
- name: Upload HTML coverage report
322+
uses: actions/upload-artifact@v4
325323
with:
326-
name: coverage-unit
327-
path: coverage/
324+
name: coverage-html
325+
path: htmlcov/
326+
retention-days: 7
328327
continue-on-error: true
329328

330329
- name: Coverage summary
331330
run: |
332331
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
333-
if [ -f coverage/coverage.xml ]; then
332+
if [ -f coverage.xml ]; then
334333
echo "Coverage report generated successfully" >> $GITHUB_STEP_SUMMARY
334+
echo "" >> $GITHUB_STEP_SUMMARY
335+
echo "### TFO v2 API Features Tested:" >> $GITHUB_STEP_SUMMARY
336+
echo "- v2 endpoints: /v2/traces, /v2/metrics, /v2/logs" >> $GITHUB_STEP_SUMMARY
337+
echo "- Collector identity (tfoidentityextension)" >> $GITHUB_STEP_SUMMARY
338+
echo "- Auth headers (tfoauthextension)" >> $GITHUB_STEP_SUMMARY
335339
else
336340
echo "No coverage report available" >> $GITHUB_STEP_SUMMARY
337341
fi
@@ -347,7 +351,9 @@ jobs:
347351
steps:
348352
- name: Generate summary
349353
run: |
350-
echo "## ${{ env.PRODUCT_NAME }} - CI Results" >> $GITHUB_STEP_SUMMARY
354+
echo "## ${{ env.PRODUCT_NAME }} v${{ env.VERSION }} - CI Results" >> $GITHUB_STEP_SUMMARY
355+
echo "" >> $GITHUB_STEP_SUMMARY
356+
echo "**TFO-Collector Version:** ${{ env.TFO_COLLECTOR_VERSION }}" >> $GITHUB_STEP_SUMMARY
351357
echo "" >> $GITHUB_STEP_SUMMARY
352358
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
353359
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
@@ -358,6 +364,11 @@ jobs:
358364
echo "| Security | ${{ needs.security.result }} |" >> $GITHUB_STEP_SUMMARY
359365
echo "| Coverage | ${{ needs.coverage.result }} |" >> $GITHUB_STEP_SUMMARY
360366
echo "" >> $GITHUB_STEP_SUMMARY
367+
echo "### TFO v2 API Features" >> $GITHUB_STEP_SUMMARY
368+
echo "- v2 endpoints: /v2/traces, /v2/metrics, /v2/logs" >> $GITHUB_STEP_SUMMARY
369+
echo "- Collector identity (aligned with tfoidentityextension)" >> $GITHUB_STEP_SUMMARY
370+
echo "- Auth headers (aligned with tfoauthextension)" >> $GITHUB_STEP_SUMMARY
371+
echo "" >> $GITHUB_STEP_SUMMARY
361372
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
362373
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
363374
echo "**Triggered by:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY

Makefile

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
# Build configuration
99
PRODUCT_NAME := TelemetryFlow Python SDK
10-
VERSION ?= 1.1.1
10+
VERSION ?= 1.1.2
11+
TFO_COLLECTOR_VERSION := 1.1.2
12+
OTEL_VERSION := 0.142.0
13+
OTEL_PYTHON_SDK_VERSION := 1.29.0
1114
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
1215
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
1316
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
@@ -102,8 +105,16 @@ help:
102105
@echo " make release-check - Check release readiness"
103106
@echo " make docs - Show documentation locations"
104107
@echo ""
108+
@echo "$(YELLOW)TFO v2 API Features:$(NC)"
109+
@echo " - v2 endpoints: /v2/traces, /v2/metrics, /v2/logs"
110+
@echo " - Collector identity (tfoidentityextension)"
111+
@echo " - Auth headers (tfoauthextension)"
112+
@echo ""
105113
@echo "$(YELLOW)Configuration:$(NC)"
106114
@echo " VERSION=$(VERSION)"
115+
@echo " TFO_COLLECTOR_VERSION=$(TFO_COLLECTOR_VERSION)"
116+
@echo " OTEL_VERSION=$(OTEL_VERSION)"
117+
@echo " OTEL_PYTHON_SDK_VERSION=$(OTEL_PYTHON_SDK_VERSION)"
107118
@echo " GIT_COMMIT=$(GIT_COMMIT)"
108119
@echo " GIT_BRANCH=$(GIT_BRANCH)"
109120
@echo " BUILD_TIME=$(BUILD_TIME)"
@@ -412,11 +423,20 @@ ci-coverage:
412423
## Version info
413424
version:
414425
@echo "$(GREEN)$(PRODUCT_NAME)$(NC)"
415-
@echo " Version: $(VERSION)"
416-
@echo " Git Commit: $(GIT_COMMIT)"
417-
@echo " Git Branch: $(GIT_BRANCH)"
418-
@echo " Build Time: $(BUILD_TIME)"
419-
@echo " Python Version: $(PYTHON_VERSION)"
426+
@echo " Version: $(VERSION)"
427+
@echo " TFO-Collector: $(TFO_COLLECTOR_VERSION)"
428+
@echo " OTEL Collector: $(OTEL_VERSION)"
429+
@echo " OTEL Python SDK: $(OTEL_PYTHON_SDK_VERSION)"
430+
@echo " Git Commit: $(GIT_COMMIT)"
431+
@echo " Git Branch: $(GIT_BRANCH)"
432+
@echo " Build Time: $(BUILD_TIME)"
433+
@echo " Python Version: $(PYTHON_VERSION)"
434+
@echo ""
435+
@echo "$(YELLOW)TFO v2 API Features:$(NC)"
436+
@echo " - v2 endpoints: /v2/traces, /v2/metrics, /v2/logs"
437+
@echo " - Collector identity (aligned with tfoidentityextension)"
438+
@echo " - Auth headers (aligned with tfoauthextension)"
439+
@echo " - Custom endpoint paths (aligned with tfoexporter)"
420440
@echo ""
421441
@echo "$(BLUE)SDK Version Info:$(NC)"
422442
@$(PYTHON) -c "from telemetryflow.version import info; print(info())" 2>/dev/null || echo " (SDK not installed)"

pyproject.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ restapi = [
7979
"pydantic>=2.5.0",
8080
"python-dotenv>=1.0.0",
8181
]
82+
instrumentation = [
83+
"opentelemetry-instrumentation>=0.49b0",
84+
"opentelemetry-instrumentation-flask>=0.49b0",
85+
"opentelemetry-instrumentation-fastapi>=0.49b0",
86+
"opentelemetry-instrumentation-sqlalchemy>=0.49b0",
87+
"opentelemetry-instrumentation-requests>=0.49b0",
88+
"opentelemetry-instrumentation-httpx>=0.49b0",
89+
"opentelemetry-instrumentation-logging>=0.49b0",
90+
"opentelemetry-instrumentation-psycopg2>=0.49b0",
91+
"opentelemetry-instrumentation-redis>=0.49b0",
92+
]
93+
all = [
94+
"telemetryflow-sdk[http,grpc,restapi,instrumentation]",
95+
]
8296

8397
[project.urls]
8498
Homepage = "https://telemetryflow.id"
@@ -123,6 +137,11 @@ omit = [
123137
"*/tests/*",
124138
"*/__pycache__/*",
125139
"*/cli/*",
140+
# Optional middleware - excluded when framework not installed
141+
"*/middleware/flask.py",
142+
"*/middleware/fastapi.py",
143+
# Conditional imports for optional frameworks
144+
"*/middleware/__init__.py",
126145
]
127146

128147
[tool.coverage.report]
@@ -134,7 +153,7 @@ exclude_lines = [
134153
"if __name__ == .__main__.:",
135154
]
136155
show_missing = true
137-
fail_under = 80
156+
fail_under = 95
138157

139158
[tool.mypy]
140159
python_version = "3.12"

0 commit comments

Comments
 (0)