Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created June 29, 2012 18:01
Show Gist options
  • Save dkuebric/3019643 to your computer and use it in GitHub Desktop.
Save dkuebric/3019643 to your computer and use it in GitHub Desktop.
djangoware sampling patch diff
dan@ponderous:~/code/oboeware $ git diff
diff --git a/oboeware/djangoware.py b/oboeware/djangoware.py
index ae1d0aa..2c56c02 100644
--- a/oboeware/djangoware.py
+++ b/oboeware/djangoware.py
@@ -41,13 +41,15 @@ class OboeDjangoMiddleware(object):
def process_request(self, request):
import oboe
+ import random
xtr_hdr = request.META.get("HTTP_X-Trace", request.META.get("HTTP_X_TRACE"))
tracing_mode = oboe.config.get('tracing_mode')
+ sample_rate = oboe.config.get('sample_rate')
if not oboe.Context.isValid() and xtr_hdr and tracing_mode in ['always', 'through']:
oboe.Context.fromString(xtr_hdr)
- if not oboe.Context.isValid() and tracing_mode == "always":
+ if not oboe.Context.isValid() and tracing_mode == "always" and random.random() < sample_rate:
evt = oboe.Context.startTrace()
elif oboe.Context.isValid() and tracing_mode != 'never':
evt = oboe.Context.createEvent()
dan@ponderous:~/code/oboeware $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment