-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add config to set hostname tag on trace root span (#938)
- Loading branch information
1 parent
c995fa5
commit 21d207e
Showing
7 changed files
with
115 additions
and
4 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
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
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,20 @@ | ||
import functools | ||
import socket | ||
|
||
_hostname = None | ||
|
||
|
||
def _cached(func): | ||
@functools.wraps(func) | ||
def wrapper(): | ||
global _hostname | ||
if not _hostname: | ||
_hostname = func() | ||
|
||
return _hostname | ||
return wrapper | ||
|
||
|
||
@_cached | ||
def get_hostname(): | ||
return socket.gethostname() |
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
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
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,14 @@ | ||
import mock | ||
|
||
from ddtrace.internal.hostname import get_hostname | ||
|
||
|
||
@mock.patch('socket.gethostname') | ||
def test_get_hostname(socket_gethostname): | ||
# Test that `get_hostname()` just returns `socket.gethostname` | ||
socket_gethostname.return_value = 'test-hostname' | ||
assert get_hostname() == 'test-hostname' | ||
|
||
# Change the value returned by `socket.gethostname` to test the cache | ||
socket_gethostname.return_value = 'new-hostname' | ||
assert get_hostname() == 'test-hostname' |
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