Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit load generator logs via OTLP #1446

Merged
merged 9 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ the release.

## Unreleased

* [loadgenerator] emit logs via OTLP
([#1446](https://github.com/open-telemetry/opentelemetry-demo/pull/1446))
* [frontend] reset quantity when new product selected
([#1447](https://github.com/open-telemetry/opentelemetry-demo/pull/1447))
* [featureflag] deprecate in favor of flagd
Expand Down
2 changes: 1 addition & 1 deletion src/loadgenerator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ COPY ./src/loadgenerator/people.json .
ENV LOCUST_PLAYWRIGHT=1
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
RUN playwright install --with-deps chromium
ENTRYPOINT locust
ENTRYPOINT locust --skip-log-setup
27 changes: 26 additions & 1 deletion src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import os
import random
import uuid
import logging
import sys
from pythonjsonlogger import jsonlogger
from locust import HttpUser, task, between
from locust_plugins.users.playwright import PlaywrightUser, pw, PageWithRetry, event

Expand All @@ -23,8 +26,30 @@
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
from opentelemetry._logs import set_logger_provider
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
OTLPLogExporter,
)
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from opentelemetry.sdk.resources import Resource
from playwright.async_api import Route, Request

logger_provider = LoggerProvider(resource=Resource.create(
{
"service.name": "loadgenerator",
}
),)
set_logger_provider(logger_provider)

exporter = OTLPLogExporter(insecure=True)
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
handler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider)

# Attach OTLP handler to locust logger
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)

exporter = OTLPMetricExporter(insecure=True)
set_meter_provider(MeterProvider([PeriodicExportingMetricReader(exporter)]))

Expand All @@ -37,6 +62,7 @@
RequestsInstrumentor().instrument()
SystemMetricsInstrumentor().instrument()
URLLib3Instrumentor().instrument()
logging.info("Instrumentation complete")

categories = [
"binoculars",
Expand Down Expand Up @@ -64,7 +90,6 @@
people_file = open('people.json')
people = json.load(people_file)


class WebsiteUser(HttpUser):
wait_time = between(1, 10)

Expand Down
23 changes: 12 additions & 11 deletions src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ locust==2.18.2
locust_plugins==3.4.0
markupsafe==2.1.3
msgpack==1.0.7
opentelemetry-api==1.22.0
opentelemetry-exporter-otlp-proto-grpc==1.22.0
opentelemetry-instrumentation==0.43b0
opentelemetry-instrumentation-jinja2==0.43b0
opentelemetry-instrumentation-requests==0.43b0
opentelemetry-instrumentation-system-metrics==0.43b0
opentelemetry-instrumentation-urllib3==0.43b0
opentelemetry-proto==1.22.0
opentelemetry-sdk==1.22.0
opentelemetry-semantic-conventions==0.43b0
opentelemetry-util-http==0.43b0
opentelemetry-api==1.23.0
opentelemetry-exporter-otlp-proto-grpc==1.23.0
opentelemetry-instrumentation==0.44b0
opentelemetry-instrumentation-jinja2==0.44b0
opentelemetry-instrumentation-requests==0.44b0
opentelemetry-instrumentation-system-metrics==0.44b0
opentelemetry-instrumentation-urllib3==0.44b0
opentelemetry-proto==1.23.0
opentelemetry-sdk==1.23.0
opentelemetry-semantic-conventions==0.44b0
opentelemetry-util-http==0.44b0
protobuf==4.25.0
psutil==5.9.6
pyzmq==25.1.1
Expand All @@ -42,3 +42,4 @@ werkzeug==3.0.1
wrapt==1.16.0
zope-event==5.0
zope-interface==6.1
python-json-logger==2.0.7
Loading