prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  httplib patch doesn't seem to support a default pin
  I'm trying to set up `httplib` patching in my application and I'm struggling to get it to send spans with a `service` set. I am not certain, but I think that the documentation and code for the `httplib` patch in `ddtrace.contrib.httplib` is broken, and doesn't support setting up a default service to send spans as.
  
  Here's my reproduction case:
  
  ```python
  import logging
  logging.basicConfig(level=logging.DEBUG)
  
  from ddtrace import patch
  patch(httplib=True)
  
  # Code taken from the ddtrace-py docs for httplib on python 3
  from ddtrace import Pin
  import http.client
  import urllib.request
  
  # Use a Pin to specify metadata for all http requests
  Pin.override(http.client, service='httplib')
  resp = urllib.request.urlopen('https://www.datadoghq.com/')
  ```
  
  If I run that locally on the latest master, I get messages like these from the `dd-trace-agent` running on my machine:
  
  ```
  2018-11-16 14:51:47 ERROR (api.go:249) - dropping trace reason: invalid span (SpanID:11098683504101424356): span.normalize: empty `Service` (debug for more info), [name:"http.client.request" resource:"http.client.request" traceID:2003532794568525569 spanID:11098683504101424356 start:1542397906651150080 duration:274516105 meta:<key:"http.method" value:"GET" > meta:<key:"http.status_code" value:"200" > meta:<key:"http.url" value:"https://www.datadoghq.com/" > meta:<key:"system.pid" value:"29250" > type:"http" ]
  ```
  
  I did some debugging locally, and it looks like the default Pin added to the `HTTPSConnection` instance in the wrapped constructor (https://github.com/DataDog/dd-trace-py/blob/v0.16.0/ddtrace/contrib/httplib/patch.py#L19) is the one that ends up feeding the span's their service value. The pin added in the example code (as suggested by the docs) isn't having any effect. Unless there's something I'm missing, this seems like it makes sense, because the pin the docs suggest adding is on the `http.client` module, not on the classes inside nor on instances of those classes. How was that supposed to work @palazzem? 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ddtrace/contrib/httplib/__init__.py`
  Content:
  ```
  1 """
  2 Patch the built-in httplib/http.client libraries to trace all HTTP calls.
  3 
  4 
  5 Usage::
  6 
  7     # Patch all supported modules/functions
  8     from ddtrace import patch
  9     patch(httplib=True)
  10 
  11     # Python 2
  12     from ddtrace import Pin
  13     import httplib
  14     import urllib
  15 
  16     # Use a Pin to specify metadata for all http requests
  17     Pin.override(httplib, service='httplib')
  18     resp = urllib.urlopen('http://www.datadog.com/')
  19 
  20     # Python 3
  21     from ddtrace import Pin
  22     import http.client
  23     import urllib.request
  24 
  25     # Use a Pin to specify metadata for all http requests
  26     Pin.override(http.client, service='httplib')
  27     resp = urllib.request.urlopen('http://www.datadog.com/')
  28 
  29 :ref:`Headers tracing <http-headers-tracing>` is supported for this integration.
  30 """
  31 from .patch import patch, unpatch
  32 __all__ = ['patch', 'unpatch']
  33
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ddtrace/contrib/httplib/__init__.py b/ddtrace/contrib/httplib/__init__.py
  --- a/ddtrace/contrib/httplib/__init__.py
  +++ b/ddtrace/contrib/httplib/__init__.py
  @@ -1,5 +1,5 @@
   """
  -Patch the built-in httplib/http.client libraries to trace all HTTP calls.
  +Patch the built-in ``httplib``/``http.client`` libraries to trace all HTTP calls.
   
   
   Usage::
  @@ -9,23 +9,24 @@
       patch(httplib=True)
   
       # Python 2
  -    from ddtrace import Pin
       import httplib
       import urllib
   
  -    # Use a Pin to specify metadata for all http requests
  -    Pin.override(httplib, service='httplib')
       resp = urllib.urlopen('http://www.datadog.com/')
   
       # Python 3
  -    from ddtrace import Pin
       import http.client
       import urllib.request
   
  -    # Use a Pin to specify metadata for all http requests
  -    Pin.override(http.client, service='httplib')
       resp = urllib.request.urlopen('http://www.datadog.com/')
   
  +``httplib`` spans do not include a default service name. Before HTTP calls are
  +made, ensure a parent span has been started with a service name to be used for
  +spans generated from those calls::
  +
  +    with tracer.trace('main', service='my-httplib-operation'):
  +        resp = urllib.request.urlopen('http://www.datadog.com/')
  +
   :ref:`Headers tracing <http-headers-tracing>` is supported for this integration.
   """
   from .patch import patch, unpatch
  
verification_info: {"golden_diff": "diff --git a/ddtrace/contrib/httplib/__init__.py b/ddtrace/contrib/httplib/__init__.py\n--- a/ddtrace/contrib/httplib/__init__.py\n+++ b/ddtrace/contrib/httplib/__init__.py\n@@ -1,5 +1,5 @@\n \"\"\"\n-Patch the built-in httplib/http.client libraries to trace all HTTP calls.\n+Patch the built-in ``httplib``/``http.client`` libraries to trace all HTTP calls.\n \n \n Usage::\n@@ -9,23 +9,24 @@\n     patch(httplib=True)\n \n     # Python 2\n-    from ddtrace import Pin\n     import httplib\n     import urllib\n \n-    # Use a Pin to specify metadata for all http requests\n-    Pin.override(httplib, service='httplib')\n     resp = urllib.urlopen('http://www.datadog.com/')\n \n     # Python 3\n-    from ddtrace import Pin\n     import http.client\n     import urllib.request\n \n-    # Use a Pin to specify metadata for all http requests\n-    Pin.override(http.client, service='httplib')\n     resp = urllib.request.urlopen('http://www.datadog.com/')\n \n+``httplib`` spans do not include a default service name. Before HTTP calls are\n+made, ensure a parent span has been started with a service name to be used for\n+spans generated from those calls::\n+\n+    with tracer.trace('main', service='my-httplib-operation'):\n+        resp = urllib.request.urlopen('http://www.datadog.com/')\n+\n :ref:`Headers tracing <http-headers-tracing>` is supported for this integration.\n \"\"\"\n from .patch import patch, unpatch\n", "issue": "httplib patch doesn't seem to support a default pin\nI'm trying to set up `httplib` patching in my application and I'm struggling to get it to send spans with a `service` set. I am not certain, but I think that the documentation and code for the `httplib` patch in `ddtrace.contrib.httplib` is broken, and doesn't support setting up a default service to send spans as.\r\n\r\nHere's my reproduction case:\r\n\r\n```python\r\nimport logging\r\nlogging.basicConfig(level=logging.DEBUG)\r\n\r\nfrom ddtrace import patch\r\npatch(httplib=True)\r\n\r\n# Code taken from the ddtrace-py docs for httplib on python 3\r\nfrom ddtrace import Pin\r\nimport http.client\r\nimport urllib.request\r\n\r\n# Use a Pin to specify metadata for all http requests\r\nPin.override(http.client, service='httplib')\r\nresp = urllib.request.urlopen('https://www.datadoghq.com/')\r\n```\r\n\r\nIf I run that locally on the latest master, I get messages like these from the `dd-trace-agent` running on my machine:\r\n\r\n```\r\n2018-11-16 14:51:47 ERROR (api.go:249) - dropping trace reason: invalid span (SpanID:11098683504101424356): span.normalize: empty `Service` (debug for more info), [name:\"http.client.request\" resource:\"http.client.request\" traceID:2003532794568525569 spanID:11098683504101424356 start:1542397906651150080 duration:274516105 meta:<key:\"http.method\" value:\"GET\" > meta:<key:\"http.status_code\" value:\"200\" > meta:<key:\"http.url\" value:\"https://www.datadoghq.com/\" > meta:<key:\"system.pid\" value:\"29250\" > type:\"http\" ]\r\n```\r\n\r\nI did some debugging locally, and it looks like the default Pin added to the `HTTPSConnection` instance in the wrapped constructor (https://github.com/DataDog/dd-trace-py/blob/v0.16.0/ddtrace/contrib/httplib/patch.py#L19) is the one that ends up feeding the span's their service value. The pin added in the example code (as suggested by the docs) isn't having any effect. Unless there's something I'm missing, this seems like it makes sense, because the pin the docs suggest adding is on the `http.client` module, not on the classes inside nor on instances of those classes. How was that supposed to work @palazzem? \n", "before_files": [{"content": "\"\"\"\nPatch the built-in httplib/http.client libraries to trace all HTTP calls.\n\n\nUsage::\n\n    # Patch all supported modules/functions\n    from ddtrace import patch\n    patch(httplib=True)\n\n    # Python 2\n    from ddtrace import Pin\n    import httplib\n    import urllib\n\n    # Use a Pin to specify metadata for all http requests\n    Pin.override(httplib, service='httplib')\n    resp = urllib.urlopen('http://www.datadog.com/')\n\n    # Python 3\n    from ddtrace import Pin\n    import http.client\n    import urllib.request\n\n    # Use a Pin to specify metadata for all http requests\n    Pin.override(http.client, service='httplib')\n    resp = urllib.request.urlopen('http://www.datadog.com/')\n\n:ref:`Headers tracing <http-headers-tracing>` is supported for this integration.\n\"\"\"\nfrom .patch import patch, unpatch\n__all__ = ['patch', 'unpatch']\n", "path": "ddtrace/contrib/httplib/__init__.py"}], "after_files": [{"content": "\"\"\"\nPatch the built-in ``httplib``/``http.client`` libraries to trace all HTTP calls.\n\n\nUsage::\n\n    # Patch all supported modules/functions\n    from ddtrace import patch\n    patch(httplib=True)\n\n    # Python 2\n    import httplib\n    import urllib\n\n    resp = urllib.urlopen('http://www.datadog.com/')\n\n    # Python 3\n    import http.client\n    import urllib.request\n\n    resp = urllib.request.urlopen('http://www.datadog.com/')\n\n``httplib`` spans do not include a default service name. Before HTTP calls are\nmade, ensure a parent span has been started with a service name to be used for\nspans generated from those calls::\n\n    with tracer.trace('main', service='my-httplib-operation'):\n        resp = urllib.request.urlopen('http://www.datadog.com/')\n\n:ref:`Headers tracing <http-headers-tracing>` is supported for this integration.\n\"\"\"\nfrom .patch import patch, unpatch\n__all__ = ['patch', 'unpatch']\n", "path": "ddtrace/contrib/httplib/__init__.py"}]}