|
30 | 30 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31 | 31 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32 | 32 |
|
| 33 | +from elasticapm.base import Client |
33 | 34 | from elasticapm.conf import constants
|
34 | 35 | from elasticapm.transport.base import Transport
|
35 | 36 | from elasticapm.utils import compat
|
| 37 | +from elasticapm.version import VERSION |
36 | 38 |
|
37 | 39 |
|
38 | 40 | class HTTPTransportBase(Transport):
|
@@ -63,6 +65,7 @@ def __init__(
|
63 | 65 | self._config_url = "".join((base, constants.AGENT_CONFIG_PATH, tail))
|
64 | 66 | self._server_info_url = "".join((base, constants.SERVER_INFO_PATH, tail))
|
65 | 67 | super(HTTPTransportBase, self).__init__(client, compress_level=compress_level, **kwargs)
|
| 68 | + self._headers["User-Agent"] = get_user_agent(self.client) |
66 | 69 |
|
67 | 70 | def send(self, data):
|
68 | 71 | """
|
@@ -98,5 +101,16 @@ def auth_headers(self):
|
98 | 101 | return {}
|
99 | 102 |
|
100 | 103 |
|
| 104 | +def get_user_agent(client: Client) -> str: |
| 105 | + """ |
| 106 | + Compiles the user agent, which will be added as a header to all requests |
| 107 | + to the APM Server |
| 108 | + """ |
| 109 | + if client.config.service_version: |
| 110 | + return "apm-agent-python/{} ({} {})".format(VERSION, client.config.service_name, client.config.service_version) |
| 111 | + else: |
| 112 | + return "apm-agent-python/{} ({})".format(VERSION, client.config.service_name) |
| 113 | + |
| 114 | + |
101 | 115 | # left for backwards compatibility
|
102 | 116 | AsyncHTTPTransportBase = HTTPTransportBase
|
0 commit comments