-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Quick start Example] Adding example with Sinatra (#2319)
* Adding example with Sinatra * Updating image name * Update docker-compose.yaml
- Loading branch information
1 parent
dccad6a
commit 8c89362
Showing
12 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ruby:3.1.2-alpine | ||
WORKDIR /usr/src/app | ||
|
||
COPY Gemfile Gemfile.lock . | ||
RUN apk update && apk add make gcc musl-dev && bundle install | ||
|
||
COPY . . | ||
RUN chmod 666 ./Gemfile.lock | ||
|
||
EXPOSE 8080 | ||
|
||
CMD [ "bundle", "exec", "ruby", "/usr/src/app/api.rb" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "puma", "~> 6.2.1" | ||
gem "sinatra", "~> 3.0.5" | ||
|
||
gem "opentelemetry-sdk", "~> 1.2" | ||
gem "opentelemetry-exporter-otlp", "~> 0.24" | ||
gem "opentelemetry-instrumentation-sinatra", "~> 0.21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
google-protobuf (3.22.2-x86_64-darwin) | ||
googleapis-common-protos-types (1.5.0) | ||
google-protobuf (~> 3.14) | ||
mustermann (3.0.0) | ||
ruby2_keywords (~> 0.0.1) | ||
nio4r (2.5.9) | ||
opentelemetry-api (1.1.0) | ||
opentelemetry-common (0.19.6) | ||
opentelemetry-api (~> 1.0) | ||
opentelemetry-exporter-otlp (0.24.0) | ||
google-protobuf (~> 3.19) | ||
googleapis-common-protos-types (~> 1.3) | ||
opentelemetry-api (~> 1.1) | ||
opentelemetry-common (~> 0.19.6) | ||
opentelemetry-sdk (~> 1.2) | ||
opentelemetry-semantic_conventions | ||
opentelemetry-instrumentation-base (0.21.1) | ||
opentelemetry-api (~> 1.0) | ||
opentelemetry-registry (~> 0.1) | ||
opentelemetry-instrumentation-rack (0.22.1) | ||
opentelemetry-api (~> 1.0) | ||
opentelemetry-common (~> 0.19.3) | ||
opentelemetry-instrumentation-base (~> 0.21.0) | ||
opentelemetry-instrumentation-sinatra (0.21.5) | ||
opentelemetry-api (~> 1.0) | ||
opentelemetry-common (~> 0.19.3) | ||
opentelemetry-instrumentation-base (~> 0.21.0) | ||
opentelemetry-instrumentation-rack (~> 0.21) | ||
opentelemetry-registry (0.2.0) | ||
opentelemetry-api (~> 1.1) | ||
opentelemetry-sdk (1.2.0) | ||
opentelemetry-api (~> 1.1) | ||
opentelemetry-common (~> 0.19.3) | ||
opentelemetry-registry (~> 0.2) | ||
opentelemetry-semantic_conventions | ||
opentelemetry-semantic_conventions (1.8.0) | ||
opentelemetry-api (~> 1.0) | ||
puma (6.2.1) | ||
nio4r (~> 2.0) | ||
rack (2.2.6.4) | ||
rack-protection (3.0.5) | ||
rack | ||
ruby2_keywords (0.0.5) | ||
sinatra (3.0.5) | ||
mustermann (~> 3.0) | ||
rack (~> 2.2, >= 2.2.4) | ||
rack-protection (= 3.0.5) | ||
tilt (~> 2.0) | ||
tilt (2.1.0) | ||
|
||
PLATFORMS | ||
x86_64-darwin-21 | ||
|
||
DEPENDENCIES | ||
opentelemetry-exporter-otlp (~> 0.24) | ||
opentelemetry-instrumentation-sinatra (~> 0.21) | ||
opentelemetry-sdk (~> 1.2) | ||
puma (~> 6.2.1) | ||
sinatra (~> 3.0.5) | ||
|
||
BUNDLED WITH | ||
2.3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Quick Start - Ruby app with OpenTelemetry and Tracetest | ||
|
||
> [Read the detailed recipe for setting up OpenTelemetry Collector with Tractest in our documentation.](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-without-a-trace-data-store) | ||
This is a simple quick start on how to configure a Ruby app (with [Sinatra](https://sinatrarb.com/) framework) to use OpenTelemetry instrumentation with traces, and Tracetest for enhancing your e2e and integration tests with trace-based testing. | ||
|
||
To run it just execute `docker compose up` on this folder. | ||
|
||
Feel free to check out the [docs](https://docs.tracetest.io/), and join our [Discord Community](https://discord.gg/8MtcMrQNbX) for more info! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "sinatra" | ||
|
||
require "opentelemetry/sdk" | ||
require "opentelemetry/exporter/otlp" | ||
require "opentelemetry/instrumentation/sinatra" | ||
|
||
set :port, 8080 | ||
|
||
OpenTelemetry::SDK.configure do |c| | ||
c.use "OpenTelemetry::Instrumentation::Sinatra" | ||
end | ||
|
||
error do | ||
OpenTelemetry::Trace.current_span.record_exception(env['sinatra.error']) | ||
end | ||
|
||
get '/hello' do | ||
'Hello World' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
version: '3' | ||
services: | ||
app: | ||
image: quick-start-ruby-sinatra | ||
platform: linux/amd64 | ||
build: . | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- APP_ENV=production | ||
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4318/v1/traces | ||
- OTEL_SERVICE_NAME=app | ||
|
||
tracetest: | ||
image: kubeshop/tracetest:latest | ||
platform: linux/amd64 | ||
volumes: | ||
- type: bind | ||
source: ./tracetest/tracetest-config.yaml | ||
target: /app/tracetest.yaml | ||
- type: bind | ||
source: ./tracetest/tracetest-provision.yaml | ||
target: /app/provisioning.yaml | ||
ports: | ||
- 11633:11633 | ||
command: --provisioning-file /app/provisioning.yaml | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
otel-collector: | ||
condition: service_started | ||
healthcheck: | ||
test: ["CMD", "wget", "--spider", "localhost:11633"] | ||
interval: 1s | ||
timeout: 3s | ||
retries: 60 | ||
environment: | ||
TRACETEST_DEV: ${TRACETEST_DEV} | ||
|
||
postgres: | ||
image: postgres:14 | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
healthcheck: | ||
test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" | ||
interval: 1s | ||
timeout: 5s | ||
retries: 60 | ||
|
||
otel-collector: | ||
image: otel/opentelemetry-collector-contrib:0.59.0 | ||
command: | ||
- "--config" | ||
- "/otel-local-config.yaml" | ||
volumes: | ||
- ./tracetest/collector.config.yaml:/otel-local-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type: Test | ||
spec: | ||
name: Call Ruby API | ||
trigger: | ||
type: http | ||
httpRequest: | ||
url: http://app:8080/hello | ||
method: GET | ||
headers: | ||
- key: Content-Type | ||
value: application/json | ||
specs: | ||
- selector: span[tracetest.span.type="http" name="GET /hello" http.method="GET"] | ||
assertions: | ||
- attr:http.status_code = 200 | ||
- attr:tracetest.span.duration < 500ms |
26 changes: 26 additions & 0 deletions
26
examples/quick-start-ruby-sinatra/tracetest/collector.config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
processors: | ||
batch: | ||
timeout: 100ms | ||
|
||
exporters: | ||
logging: | ||
loglevel: debug | ||
otlp/1: | ||
endpoint: tracetest:21321 | ||
# Send traces to Tracetest. | ||
# Read more in docs here: https://docs.tracetest.io/configuration/connecting-to-data-stores/opentelemetry-collector | ||
tls: | ||
insecure: true | ||
|
||
service: | ||
pipelines: | ||
traces/1: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [otlp/1] |
7 changes: 7 additions & 0 deletions
7
examples/quick-start-ruby-sinatra/tracetest/tracetest-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
postgres: | ||
host: postgres | ||
user: postgres | ||
password: postgres | ||
port: 5432 | ||
dbname: postgres | ||
params: sslmode=disable |
16 changes: 16 additions & 0 deletions
16
examples/quick-start-ruby-sinatra/tracetest/tracetest-provision.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
type: PollingProfile | ||
spec: | ||
name: Default | ||
strategy: periodic | ||
default: true | ||
periodic: | ||
retryDelay: 5s | ||
timeout: 10m | ||
|
||
--- | ||
type: DataStore | ||
spec: | ||
name: OpenTelemetry Collector | ||
type: otlp | ||
isdefault: true |