@@ -85,13 +85,13 @@ def __init__(
85
85
self ,
86
86
cov_storage : CodecovCoverageStorageManager ,
87
87
repository_token : str ,
88
- profiling_id : str ,
88
+ code : str ,
89
89
codecov_endpoint : str ,
90
90
untracked_export_rate : float ,
91
91
):
92
92
self ._cov_storage = cov_storage
93
93
self ._repository_token = repository_token
94
- self ._profiling_id = profiling_id
94
+ self ._code = code
95
95
self ._codecov_endpoint = codecov_endpoint
96
96
self ._untracked_export_rate = untracked_export_rate
97
97
@@ -128,7 +128,7 @@ def export(self, spans):
128
128
res = requests .post (
129
129
url ,
130
130
headers = {"Authorization" : f"repotoken { self ._repository_token } " },
131
- json = {"profiling" : self ._profiling_id },
131
+ json = {"profiling" : self ._code },
132
132
)
133
133
res .raise_for_status ()
134
134
except requests .RequestException :
@@ -149,63 +149,54 @@ def get_codecov_opentelemetry_instances(
149
149
repository_token : str ,
150
150
sample_rate : float ,
151
151
untracked_export_rate : float ,
152
+ code : str ,
152
153
filters : Optional [Dict ] = None ,
153
- profiling_identifier : Optional [str ] = None ,
154
+ version_identifier : Optional [str ] = None ,
154
155
environment : Optional [str ] = None ,
155
- profiling_id : Optional [ str ] = None ,
156
+ needs_version_creation : bool = True ,
156
157
codecov_endpoint : str = None ,
157
158
writeable_folder : str = None ,
158
159
) -> Tuple [CodecovCoverageGenerator , CoverageExporter ]:
159
160
"""
160
161
Entrypoint for getting a span processor/span exporter
161
162
pair for getting profiling data into codecov
162
163
163
- Notice that either `profiling_id` or `profiling_identifier` and `environment` need to be set.
164
- If `profiling_id` is set, we just use it directly on the exporter. If not, we will use
165
- `profiling_identifier` and `environment` to generate fetch a `profiling_id` from the
166
- database
167
-
168
164
Args:
169
165
repository_token (str): The profiling-capable authentication token
170
166
sample_rate (float): The sampling rate for codecov
171
167
untracked_export_rate (float): Description
172
168
filters (Optional[Dict], optional): A dictionary of filters for determining which
173
169
spans should have its coverage tracked
174
- profiling_identifier (Optional[str], optional): The identifier for what profiling one is doing
170
+ version_identifier (Optional[str], optional): The identifier for what
171
+ software version is being profiled
175
172
environment (Optional[str], optional): Which environment this profiling is running on
176
- profiling_id (Optional[ str], optional ): Description
173
+ code ( str): The code of this profiling
177
174
codecov_endpoint (str, optional): For configuring the endpoint in case
178
175
the user is in enterprise (not supported yet). Default is "https://api.codecov.io/"
179
176
writeable_folder (str, optional): A folder that is guaranteed to be write-able
180
177
in the system. It's only used for temporary files, and nothing is expected
181
178
to live very long in there.
182
179
"""
183
180
codecov_endpoint = codecov_endpoint or "https://api.codecov.io"
184
- if profiling_id is None :
185
- if profiling_identifier is None or environment is None :
186
- raise UnableToStartProcessorException (
187
- "Codecov profiling needs either the id or identifier + environment"
188
- )
181
+ if code is None :
182
+ raise UnableToStartProcessorException ("Codecov profiling needs a code set" )
183
+ if needs_version_creation and version_identifier and environment :
189
184
response = requests .post (
190
185
urllib .parse .urljoin (codecov_endpoint , "/profiling/versions" ),
191
186
json = {
192
- "version_identifier" : profiling_identifier ,
187
+ "version_identifier" : version_identifier ,
193
188
"environment" : environment ,
189
+ "code" : code ,
194
190
},
195
191
headers = {"Authorization" : f"repotoken { repository_token } " },
196
192
)
197
193
try :
198
194
response .raise_for_status ()
199
195
except requests .HTTPError :
200
196
raise UnableToStartProcessorException ()
201
- profiling_id = response .json ()["external_id" ]
202
197
manager = CodecovCoverageStorageManager (writeable_folder , filters or {})
203
198
generator = CodecovCoverageGenerator (manager , sample_rate )
204
199
exporter = CoverageExporter (
205
- manager ,
206
- repository_token ,
207
- profiling_id ,
208
- codecov_endpoint ,
209
- untracked_export_rate ,
200
+ manager , repository_token , code , codecov_endpoint , untracked_export_rate ,
210
201
)
211
202
return (generator , exporter )
0 commit comments