-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W-11859214: A.8.2 Respect semantic conventions of span generation in …
…DB connector
- Loading branch information
Showing
20 changed files
with
1,717 additions
and
18 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
109 changes: 109 additions & 0 deletions
109
.../db/internal/domain/connection/datasource/ConnectionBasedDbConnectionTracingMetadata.java
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,109 @@ | ||
/* | ||
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.extension.db.internal.domain.connection.datasource; | ||
|
||
import static org.mule.db.commons.internal.domain.connection.ConnectionTracingMetadataUtils.getHostFrom; | ||
import static org.mule.db.commons.internal.domain.connection.ConnectionTracingMetadataUtils.getProtocolFrom; | ||
import static org.mule.extension.db.internal.domain.connection.datasource.NoConnectionMetadata.getMetadata; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import static java.util.Optional.empty; | ||
import static java.util.Optional.ofNullable; | ||
|
||
import org.mule.db.commons.internal.domain.connection.DbConnectionTracingMetadata; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DatabaseMetaData; | ||
import java.sql.SQLException; | ||
import java.util.Optional; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** | ||
* A {@link DbConnectionTracingMetadata} based on the connection metadata | ||
*/ | ||
public class ConnectionBasedDbConnectionTracingMetadata implements DbConnectionTracingMetadata { | ||
|
||
public static final String UNSET = "unset"; | ||
private static final Logger LOGGER = getLogger(ConnectionBasedDbConnectionTracingMetadata.class); | ||
private final Connection connection; | ||
private DatabaseMetaData metadata; | ||
|
||
public ConnectionBasedDbConnectionTracingMetadata(Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
@Override | ||
public String getDbSystem() { | ||
try { | ||
return getMetaData().getDatabaseProductName(); | ||
} catch (SQLException e) { | ||
LOGGER.debug("Unable to retrieve connection metadata for tracing.", e); | ||
} | ||
|
||
return UNSET; | ||
} | ||
|
||
private DatabaseMetaData getMetaData() throws SQLException { | ||
// In case the information cannot be retrieved it will not be present. | ||
if (metadata == null) { | ||
try { | ||
metadata = connection.getMetaData(); | ||
} catch (Throwable e) { | ||
LOGGER.debug("Unable to retrieve database metadata from connection", e); | ||
metadata = getMetadata(); | ||
} | ||
|
||
} | ||
|
||
return metadata; | ||
} | ||
|
||
@Override | ||
public String getConnectionString() { | ||
try { | ||
return getMetaData().getURL(); | ||
} catch (SQLException e) { | ||
LOGGER.debug("Unable to retrieve connection metadata for tracing.", e); | ||
} | ||
|
||
return UNSET; | ||
} | ||
|
||
@Override | ||
public String getUser() { | ||
try { | ||
return getMetaData().getUserName(); | ||
} catch (SQLException e) { | ||
LOGGER.debug("Unable to retrieve connection metadata for tracing.", e); | ||
} | ||
|
||
return UNSET; | ||
} | ||
|
||
@Override | ||
public Optional<String> getPeerName() { | ||
try { | ||
return ofNullable(getHostFrom(getMetaData().getURL())); | ||
} catch (SQLException e) { | ||
LOGGER.debug("Unable to retrieve connection metadata for tracing.", e); | ||
} | ||
|
||
return empty(); | ||
} | ||
|
||
@Override | ||
public Optional<String> getPeerTransport() { | ||
try { | ||
return ofNullable(getProtocolFrom(getMetaData().getURL())); | ||
} catch (SQLException e) { | ||
LOGGER.debug("Unable to retrieve connection metadata for tracing.", e); | ||
} | ||
|
||
return empty(); | ||
} | ||
} |
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
Oops, something went wrong.