Skip to content

Commit

Permalink
Merge pull request #270 from norcalipa/norcalipa/opentelemetry-redis
Browse files Browse the repository at this point in the history
Adding opentelemetry config for redis
  • Loading branch information
norcalipa authored Nov 17, 2024
2 parents 6d29abb + d36c868 commit dea5215
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 178 deletions.
3 changes: 3 additions & 0 deletions crank/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
from pathlib import Path

from dotenv import load_dotenv
from newrelic import agent
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.instrumentation.redis import RedisInstrumentor

load_dotenv()
DjangoInstrumentor().instrument(is_sql_commentor_enabled=True)
RedisInstrumentor().instrument()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
Expand Down
200 changes: 29 additions & 171 deletions newrelic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,184 +72,42 @@ log_file = stdout
# NEW_RELIC_LOG_LEVEL environment variable.
log_level = info

# High Security Mode enforces certain security settings, and prevents
# them from being overridden, so that no sensitive data is sent to New
# Relic. Enabling High Security Mode means that request parameters are
# not collected and SQL can not be sent to New Relic in its raw form.
# To activate High Security Mode, it must be set to 'true' in this
# local .ini configuration file AND be set to 'true' in the
# server-side configuration in the New Relic user interface. It can
# also be set using the NEW_RELIC_HIGH_SECURITY environment variable.
# For details, see
# https://docs.newrelic.com/docs/subscriptions/high-security
high_security = false

# The Python Agent will attempt to connect directly to the New
# Relic service. If there is an intermediate firewall between
# your host and the New Relic service that requires you to use a
# HTTP proxy, then you should set both the "proxy_host" and
# "proxy_port" settings to the required values for the HTTP
# proxy. The "proxy_user" and "proxy_pass" settings should
# additionally be set if proxy authentication is implemented by
# the HTTP proxy. The "proxy_scheme" setting dictates what
# protocol scheme is used in talking to the HTTP proxy. This
# would normally always be set as "http" which will result in the
# agent then using a SSL tunnel through the HTTP proxy for end to
# end encryption.
# See https://docs.newrelic.com/docs/apm/agents/python-agent/configuration/python-agent-configuration/#proxy
# for information on proxy configuration via environment variables.
# proxy_scheme = http
# proxy_host = hostname
# proxy_port = 8080
# proxy_user =
# proxy_pass =

# Capturing request parameters is off by default. To enable the
# capturing of request parameters, first ensure that the setting
# "attributes.enabled" is set to "true" (the default value), and
# then add "request.parameters.*" to the "attributes.include"
# setting. For details about attributes configuration, please
# consult the documentation.
# attributes.include = request.parameters.*

# The transaction tracer captures deep information about slow
# transactions and sends this to the UI on a periodic basis. The
# transaction tracer is enabled by default. Set this to "false"
# to turn it off.
transaction_tracer.enabled = true

# Threshold in seconds for when to collect a transaction trace.
# When the response time of a controller action exceeds this
# threshold, a transaction trace will be recorded and sent to
# the UI. Valid values are any positive float value, or (default)
# "apdex_f", which will use the threshold for a dissatisfying
# Apdex controller action - four times the Apdex T value.
transaction_tracer.transaction_threshold = apdex_f

# When the transaction tracer is on, SQL statements can
# optionally be recorded. The recorder has three modes, "off"
# which sends no SQL, "raw" which sends the SQL statement in its
# original form, and "obfuscated", which strips out numeric and
# string literals.
transaction_tracer.record_sql = obfuscated

# Threshold in seconds for when to collect stack trace for a SQL
# call. In other words, when SQL statements exceed this
# threshold, then capture and send to the UI the current stack
# trace. This is helpful for pinpointing where long SQL calls
# originate from in an application.
transaction_tracer.stack_trace_threshold = 0.5

# Determines whether the agent will capture query plans for slow
# SQL queries. Only supported in MySQL and PostgreSQL. Set this
# to "false" to turn it off.
transaction_tracer.explain_enabled = true

# Threshold for query execution time below which query plans
# will not not be captured. Relevant only when "explain_enabled"
# is true.
transaction_tracer.explain_threshold = 0.5

# Space separated list of function or method names in form
# 'module:function' or 'module:class.function' for which
# additional function timing instrumentation will be added.
transaction_tracer.function_trace =

# The error collector captures information about uncaught
# exceptions or logged exceptions and sends them to UI for
# viewing. The error collector is enabled by default. Set this
# to "false" to turn it off. For more details on errors, see
# https://docs.newrelic.com/docs/apm/agents/manage-apm-agents/agent-data/manage-errors-apm-collect-ignore-or-mark-expected/
error_collector.enabled = true

# To stop specific errors from reporting to the UI, set this to
# a space separated list of the Python exception type names to
# ignore. The exception name should be of the form 'module:class'.
error_collector.ignore_classes =

# Expected errors are reported to the UI but will not affect the
# Apdex or error rate. To mark specific errors as expected, set this
# to a space separated list of the Python exception type names to
# expected. The exception name should be of the form 'module:class'.
error_collector.expected_classes =

# Browser monitoring is the Real User Monitoring feature of the UI.
# For those Python web frameworks that are supported, this
# setting enables the auto-insertion of the browser monitoring
# JavaScript fragments.
browser_monitoring.auto_instrument = true

# A thread profiling session can be scheduled via the UI when
# this option is enabled. The thread profiler will periodically
# capture a snapshot of the call stack for each active thread in
# the application to construct a statistically representative
# call tree. For more details on the thread profiler tool, see
# https://docs.newrelic.com/docs/apm/apm-ui-pages/events/thread-profiler-tool/
thread_profiler.enabled = true

# Your application deployments can be recorded through the
# New Relic REST API. To use this feature provide your API key
# below then use the `newrelic-admin record-deploy` command.
# This can also be set using the NEW_RELIC_API_KEY
# environment variable.
# api_key =

# Distributed tracing lets you see the path that a request takes
# through your distributed system. For more information, please
# consult our distributed tracing planning guide.
# https://docs.newrelic.com/docs/transition-guide-distributed-tracing
distributed_tracing.enabled = true

# This setting enables log decoration, the forwarding of log events,
# and the collection of logging metrics if these sub-feature
# configurations are also enabled. If this setting is false, no
# logging instrumentation features are enabled. This can also be
# set using the NEW_RELIC_APPLICATION_LOGGING_ENABLED environment
# variable.
# application_logging.enabled = true

# If true, the agent captures log records emitted by your application
# and forwards them to New Relic. `application_logging.enabled` must
# also be true for this setting to take effect. You can also set
# this using the NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED
# environment variable.
# application_logging.forwarding.enabled = true
[application_server]
enabled = true

# If true, the agent decorates logs with metadata to link to entities,
# hosts, traces, and spans. `application_logging.enabled` must also
# be true for this setting to take effect. This can also be set
# using the NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED
# environment variable.
# application_logging.local_decorating.enabled = true
[import_hook:django]
enabled = true

# If true, the agent captures metrics related to the log lines
# being sent up by your application. This can also be set
# using the NEW_RELIC_APPLICATION_LOGGING_METRICS_ENABLED
# environment variable.
# application_logging.metrics.enabled = true
[import_hook:redis]
enabled = true

[import_hook:opentelemetry]
enabled = true

# ---------------------------------------------------------------------------
[attributes]
# Attributes are key-value pairs that you can add to your events, transactions, and errors.
# You can use them to filter and group your data in New Relic.
# For example, you can add the environment (production, staging, etc.) as an attribute.
# attributes.include = request.parameters.*, response.headers.*, custom.attribute

#
# The application environments. These are specific settings which
# override the common environment settings. The settings related to a
# specific environment will be used when the environment argument to the
# newrelic.agent.initialize() function has been defined to be either
# "development", "test", "staging" or "production".
#
[transaction_tracer]
enabled = true
transaction_threshold = apdex_f
record_sql = obfuscated
stack_trace_threshold = 0.5

[newrelic:development]
monitor_mode = false
[error_collector]
enabled = true
capture_events = true

[newrelic:test]
monitor_mode = false
[distributed_tracing]
enabled = true

[newrelic:staging]
app_name = Python Application (Staging)
monitor_mode = true
[thread_profiler]
enabled = true

[newrelic:production]
monitor_mode = true
[cross_application_tracer]
enabled = true

# ---------------------------------------------------------------------------
[agent_limits]
transaction_traces_nodes = 2000
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ distlib==0.3.8
Django==4.2.16
django-allauth==0.63.6
django-bootstrap5==23.3
django-cache-headers==0.4
django-cors-headers==4.3.1
django-db-connection-pool==1.2.5
django-extensions==3.2.3
Expand Down Expand Up @@ -52,13 +53,13 @@ newrelic==10.0.0
nose==1.3.7
numpy==2.1.2
oauthlib==3.2.2
opentelemetry-api==1.24.0
opentelemetry-instrumentation==0.45b0
opentelemetry-instrumentation-django==0.45b0
opentelemetry-instrumentation-wsgi==0.45b0
opentelemetry-sdk==1.24.0
opentelemetry-semantic-conventions==0.45b0
opentelemetry-util-http==0.45b0
opentelemetry-api==1.28.1
opentelemetry-instrumentation==0.49b1
opentelemetry-instrumentation-django==0.49b1
opentelemetry-instrumentation-redis==0.49b1
opentelemetry-instrumentation-wsgi==0.49b1
opentelemetry-semantic-conventions==0.49b1
opentelemetry-util-http==0.49b1
packaging==23.2
pandas==2.2.3
platformdirs==4.2.0
Expand Down

0 comments on commit dea5215

Please sign in to comment.