Skip to content

Commit

Permalink
add opentelemetry auto-instrumetation
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Dec 18, 2023
1 parent 8c006d7 commit 3fe30bf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</p>

# policy-man

OPA based policy engine.

## How to use
Expand All @@ -21,7 +22,6 @@ make build

### Start the policy-man


```shell
./policy-man -h

Expand All @@ -46,7 +46,7 @@ Flags:
### Evaluate the input by a policy list
Only `allow` and `deny` will be evaluated. If the variable `allow` be evaluated as false, or the variable `deny` be
Only `allow` and `deny` will be evaluated. If the variable `allow` be evaluated as false, or the variable `deny` be
evaluated as true, The policy will be evaluated as false.
```shell
Expand All @@ -64,7 +64,8 @@ $ curl -X POST http://localhost:8090/evaluate/policies -H 'Content-Type: applica
### Use Swagger UI
Open internet browser and navigate to the url [http://localhost:8090/swagger/index.html](http://localhost:8090/swagger/index.html).
Open internet browser and navigate to the
url [http://localhost:8090/swagger/index.html](http://localhost:8090/swagger/index.html).
View and Call APIs on the page of swagger UI.
### Update OpenAPI documentation
Expand All @@ -79,6 +80,15 @@ make api_doc
All the above commands are written to the file [Makefile](./Makefile), You can also use commands in the chapter
[Build from source](#Build from source) directly to update these files.
## Dependencies File
### Dependencies File
All third-party related content is listed in the [DEPENDENCIES](DEPENDENCIES) file.
### Telemetry Instrumentation
We can instrument the policy-man with open-telemetry metrics and traces using the auto-instrumentation feature from
the [open-telemetry project](https://github.com/open-telemetry/opentelemetry-go-instrumentation).
This automatically generates required data for all HTTP requests.
All third-party related content is listed in the [DEPENDENCIES](DEPENDENCIES) file.
Sample working example can be found [here](telemetry). The example uses jaeger as OTEL collector but can be used with
any OTEL based collector. Jager UI can be accessed at http://localhost:16686/ .
52 changes: 52 additions & 0 deletions telemetry/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: "3.9"

networks:
default:
name: policy-man
driver: bridge

services:
policy-man:
depends_on:
- jaeger
build:
context: ../
dockerfile: Dockerfile
pid: "host"
ports:
- "8090:8090"
volumes:
- /proc:/host/proc
command: --host=0.0.0.0
container_name: policy-man
go-auto:
depends_on:
- policy-man
image: ghcr.io/open-telemetry/opentelemetry-go-instrumentation/autoinstrumentation-go:v0.9.0-alpha
privileged: true
pid: "host"
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
- OTEL_GO_AUTO_TARGET_EXE=/usr/bin/policy-man
- OTEL_GO_AUTO_INCLUDE_DB_STATEMENT=true
- OTEL_SERVICE_NAME=policy-man
- OTEL_PROPAGATORS=tracecontext,baggage
- CGO_ENABLED=1
volumes:
- /proc:/host/proc
container_name: go-auto-instrumentation

jaeger:
image: jaegertracing/all-in-one:latest
ports:
- "16686:16686"
- "14268:14268"
environment:
- COLLECTOR_OTLP_ENABLED=true
- LOG_LEVEL=debug
deploy:
resources:
limits:
memory: 300M
restart: unless-stopped
container_name: jaeger

0 comments on commit 3fe30bf

Please sign in to comment.