-
Notifications
You must be signed in to change notification settings - Fork 55
Open Telemetry Transport #1229
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
Open
ansoniS1
wants to merge
55
commits into
master
Choose a base branch
from
otlp_2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Open Telemetry Transport #1229
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
d34edd4
initial
ansoniS1 15c0403
remove Oauth2 settings from print_useful_settings
ansoniS1 57d50cc
bump otel libs to latest
ansoniS1 e3aca57
get rid of opentelemetry library
ansoniS1 bc0b572
add requirement
ansoniS1 22f3bb9
update requirements
ansoniS1 5c3f188
change import
ansoniS1 00116f6
update generated protobuf OTEL files
ansoniS1 069ef52
update import
ansoniS1 19eca12
try alternative import style
ansoniS1 ae430bb
move import
ansoniS1 d9c9779
Integration tests and kuberentes_monitor / k8s implementation
alesnovak-s1 9462017
Prefix oauth configurations
ansoniS1 1ffd6a2
rename methods to use oauth_ prefix
ansoniS1 1884372
Re-factor client methods to util
ansoniS1 0217af5
first test
ansoniS1 8b163f0
update reference to ssl
ansoniS1 a4bf7e1
remove `__` from __receive_response_status
ansoniS1 8431a88
DTIN-3315 (#1223)
alesnovak-s1 5fe0df4
Removing unused queue import, which is not supported in python2. conc…
alesnovak-s1 1e2c4ce
Project import generated by Copybara. (#1232)
alesnovak-s1 e17c449
Fixing windows unit tests (#1234)
alesnovak-s1 447682d
EventID Parsing (#1235)
alesnovak-s1 c5246b5
DTIN-2346: Set monitor attribute when message_log_template is used (#…
jmakar-s1 b366b54
Integration tests and kuberentes_monitor / k8s implementation
alesnovak-s1 238c883
Update new LogWatcher `add_log_config` signature into unit-tests
ansoniS1 7c56dde
Merge branch 'master' into otlp_2
ansoniS1 393f6e2
Revert "EventID Parsing (#1235)"
ansoniS1 5e228ea
Revert "Fixing windows unit tests (#1234)"
ansoniS1 ef62d8f
Revert "Project import generated by Copybara. (#1232)"
ansoniS1 e586a03
Revert "Removing unused queue import, which is not supported in pytho…
ansoniS1 c39a1b4
revert all the changes (very messy)
ansoniS1 b709d12
revert all the changes (very messy)
ansoniS1 1036729
Enable OAuth/OTLP configs to be EnvAware
ansoniS1 adea362
add opentelemetry thirdparty to our docker container
ansoniS1 116086b
add reference worker_config server_url
ansoniS1 4c26218
fix worker config reference
ansoniS1 a9042ab
fix flow with selecting server_url
ansoniS1 42e35ce
remove requirement for scalyr_server to be set (server_url is adequate)
ansoniS1 08c913a
Handle implicit ports
ansoniS1 a4e986e
allow server_url or scalyr_server for setting otlp endpoint
ansoniS1 e20f0dc
add debug
ansoniS1 a615853
implement some statistics
ansoniS1 05dbfd0
add basic auth support
ansoniS1 6362d2b
fix header typo
ansoniS1 81278d9
add rename_logfile support
ansoniS1 b851c34
likely fix the rename_logfile support
ansoniS1 b7d7a30
Merge remote-tracking branch 'origin/master' into otlp_2
ansoniS1 e4a076e
Merge remote-tracking branch 'origin/master' into otlp_2
ansoniS1 af71d6c
add opentelemetry as thirdparty in aio
ansoniS1 af50ba2
fix handling of session_info and log/thread
ansoniS1 75334ef
Fix order of attribute encoding
ansoniS1 300584f
quick test
ansoniS1 62dc253
add log and thread last
ansoniS1 d627f14
avoid ambiguous resolution between event and session variables
ansoniS1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,97 @@ | ||
| import datetime | ||
| import json | ||
| import urllib | ||
| from base64 import b64encode | ||
|
|
||
| from urllib.parse import urlparse | ||
|
|
||
| import scalyr_agent.scalyr_logging as scalyr_logging | ||
|
|
||
| import requests | ||
|
|
||
| log = scalyr_logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ClientAuth(object): | ||
| def __init__(self, configuration, headers): | ||
| log.setLevel(configuration.debug_level) | ||
| self.configuration = configuration | ||
| self.headers = headers | ||
| if self.configuration.auth == "oauth2": | ||
| self.auth = OAuth2(self.configuration, self.headers) | ||
| elif self.configuration.auth == "bearer": | ||
| self.auth = BearerToken(self.configuration, self.headers) | ||
| elif self.configuration.auth == "basic": | ||
| self.auth = Basic(self.configuration, self.headers) | ||
| else: | ||
| self.auth = NoAuth(self.configuration, self.headers) | ||
|
|
||
| def authenticate(self): | ||
| return self.auth.authenticate() | ||
|
|
||
| class NoAuth(object): | ||
| def __init__(self, configuration, headers): | ||
| self.headers = headers | ||
|
|
||
| def authenticate(self): | ||
| # Add a header just so for traceability | ||
| self.headers["x-no-custom-auth"]="true" | ||
| return True | ||
|
|
||
| # Simple Authorization Header as Bearer Token using `api_key` configuration | ||
| class BearerToken(object): | ||
| def __init__(self, configuration, headers): | ||
| headers.set("Authorization", "Bearer " + configuration.api_key) | ||
|
|
||
| def authenticate(self): | ||
| return True | ||
|
|
||
| class Basic(object): | ||
| def __init__(self, configuration, headers): | ||
| authorization_header_value = b64encode( | ||
| bytes(('' + configuration.basic_username + ":" + configuration.basic_password).encode("utf-8"))).decode('utf-8') | ||
| headers["Authorization"]="Basic " + authorization_header_value | ||
|
|
||
| def authenticate(self): | ||
| return True | ||
|
|
||
| # Implement https://datatracker.ietf.org/doc/html/rfc6749#section-4.4 flow | ||
| class OAuth2(object): | ||
| def __init__(self, configuration, headers): | ||
| self.headers = headers # Headers modified for external requests | ||
| self.client_id = configuration.oauth_client_id | ||
| self.client_secret = configuration.oauth_client_secret | ||
| self.token_url = configuration.oauth_token_url | ||
| scopes = " ".join(configuration.oauth_scopes) | ||
| # Payload Body for the token exchange | ||
| self.auth_request = "grant_type=client_credentials&scope=" + urllib.parse.quote(scopes) | ||
| # Our token to use in requests | ||
| self.token = None | ||
| # When the token expires | ||
| self.expiry_time = datetime.datetime.now() | ||
| self.verify_ssl = configuration.verify_server_certificate | ||
| # Authentication Headers for the token exchange | ||
| authorization_header_value = b64encode( bytes(('' + self.client_id + ':' + self.client_secret).encode("utf-8"))).decode('utf-8') | ||
| self.auth_headers = { "Content-Type": "application/x-www-form-urlencoded", "Authorization" : "Basic " + authorization_header_value} | ||
|
|
||
| def authenticate(self): | ||
| if self.token == None or self.expiry_time < datetime.datetime.now(): | ||
| log.info("Request/Refresh OAuth2 Token") | ||
| if not self.refresh_token(): | ||
| raise Exception("OAuth2: Unable to refresh token") | ||
| self.headers["Authorization"]="Bearer " + self.token | ||
| return True | ||
|
|
||
| def refresh_token(self): | ||
| log.log(scalyr_logging.DEBUG_LEVEL_1, "OAuth2 Token Request to %s, body: %s, headers: %s" % (self.token_url, self.auth_request, self.headers)) | ||
| resp = requests.post(self.token_url, data=self.auth_request, headers=self.auth_headers, verify=self.verify_ssl) | ||
| if resp.status_code == 200: | ||
| log.log(scalyr_logging.DEBUG_LEVEL_1, "OAUTH Response: %s" % (resp.content)) | ||
| auth_response = json.loads(resp.content) | ||
| self.token = auth_response["access_token"] | ||
| self.expiry_time = datetime.datetime.now() + datetime.timedelta(seconds=auth_response["expires_in"]) | ||
| log.log(scalyr_logging.DEBUG_LEVEL_1, "OAUTH Token: %s (expires: %s)" % (self.token, self.expiry_time)) | ||
| return True | ||
| else: | ||
| raise Exception("Unable to obtain OAuth2 Token: " + str(resp.status_code) + "(" + str(resp.content) + ")") | ||
| return False | ||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a python library for OAuth2 to avoid having an in-house implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python2 requirement paints us into some really weird corners like having to be on older versions of code that opens up security risks. This seems like the path of least resistance. I originally used the OpenTelemetry Python SDK, but had to back out of that because of no Python2 support.